diff --git a/Tutorial/GacUI_HelloWorlds/CppXml/UI/Resource.xml b/Tutorial/GacUI_HelloWorlds/CppXml/UI/Resource.xml index d49dcbe2..00697ee2 100644 --- a/Tutorial/GacUI_HelloWorlds/CppXml/UI/Resource.xml +++ b/Tutorial/GacUI_HelloWorlds/CppXml/UI/Resource.xml @@ -16,7 +16,7 @@ - + diff --git a/Tutorial/GacUI_HelloWorlds/CppXml/WinMain.cpp b/Tutorial/GacUI_HelloWorlds/CppXml/WinMain.cpp new file mode 100644 index 00000000..c5d2996a --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/CppXml/WinMain.cpp @@ -0,0 +1,7 @@ +#include +#include + +int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow) +{ + return SetupWindowsDirect2DRenderer(); +} \ No newline at end of file diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj b/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj index 864d5712..4135a90a 100644 --- a/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj +++ b/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj @@ -80,13 +80,24 @@ + + + {8018d622-66ba-4e65-9d03-bdac37ea9a54} + + + + + + + + diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj.filters b/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj.filters index 948faede..464d651d 100644 --- a/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj.filters +++ b/Tutorial/GacUI_HelloWorlds/MVVM/MVVM.vcxproj.filters @@ -13,10 +13,38 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {7285afdf-8248-4423-a988-ffbd98abbaa0} + Source Files + + UI + + + UI + + + Source Files + + + + + Resource Files + + + + + UI + + + UI + + + UI + \ No newline at end of file diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/Main.cpp b/Tutorial/GacUI_HelloWorlds/MVVM/Main.cpp index 6b0c6809..61aa4b56 100644 --- a/Tutorial/GacUI_HelloWorlds/MVVM/Main.cpp +++ b/Tutorial/GacUI_HelloWorlds/MVVM/Main.cpp @@ -1,11 +1,88 @@ -#include -#include +#include "UI/Source/HelloWorld.h" -int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow) +using namespace vl::collections; +using namespace vl::stream; +using namespace vl::regex; + +class ViewModel : public Object, public virtual vm::IViewModel { - return SetupWindowsDirect2DRenderer(); -} +private: + WString userName; + WString password; + Regex regexLcLetters; + Regex regexUcLetters; + Regex regexNumbers; + +public: + ViewModel() + :regexLcLetters(L"[a-z]") + , regexUcLetters(L"[A-Z]") + , regexNumbers(L"[0-9]") + { + } + + WString GetUserName()override + { + return userName; + } + + void SetUserName(WString value)override + { + userName = value; + UserNameErrorChanged(); + } + + WString GetUserNameError()override + { + if (userName == L"") + { + return L"User name should not be empty."; + } + return L""; + } + + WString GetPassword()override + { + return password; + } + + void SetPassword(WString value)override + { + password = value; + PasswordErrorChanged(); + } + + WString GetPasswordError()override + { + if (password == L"") + { + return L"Password should not be empty."; + } + bool containsLowerCases = regexLcLetters.Match(password); + bool containsUpperCases = regexUcLetters.Match(password); + bool containsNumbers = regexNumbers.Match(password); + if (!containsLowerCases || !containsUpperCases || !containsNumbers) + { + return L"Password should contains at least one lower case letter, one upper case letter and one digit."; + } + return L""; + } + + bool SignUp()override + { + return true; + } +}; void GuiMain() { + { + List errors; + FileStream fileStream(L"../UIRes/MVVM.bin", FileStream::ReadOnly); + auto resource = GuiResource::LoadPrecompiledBinary(fileStream, errors); + GetInstanceLoaderManager()->SetResource(L"Resource", resource); + } + helloworld::MainWindow window(new ViewModel); + window.MoveToScreenCenter(); + GetApplication()->Run(&window); } \ No newline at end of file diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Codegen.bat b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Codegen.bat new file mode 100644 index 00000000..27f6654b --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Codegen.bat @@ -0,0 +1 @@ +..\..\..\..\Tools\GacGen.exe Resource.xml \ No newline at end of file diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Resource.xml b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Resource.xml new file mode 100644 index 00000000..04e89441 --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Resource.xml @@ -0,0 +1,123 @@ + + + + + Source + GacUIReflection.h + HelloWorld + + + + ..\..\UIRes + MVVM.bin + + + + + + + + + + + + + + composeType:Absolute absolute:90 + composeType:MinSize + composeType:MinSize + composeType:MinSize + composeType:MinSize + composeType:Absolute absolute:12 + composeType:Percentage percentage:1.0 + composeType:MinSize + + + composeType:MinSize + composeType:Percentage percentage:1.0 + + + + fontFamily:{Segoe UI} size:40 antialias:true + + + + + fontFamily:{Segoe UI} size:12 antialias:true + + + + + + + + + + fontFamily:{Segoe UI} size:12 antialias:true + + + + + fontFamily:{Segoe UI} size:12 antialias:true + + + + + + + + + + fontFamily:{Segoe UI} size:12 antialias:true + + + + + + +
+
+
+
+
+
\ No newline at end of file diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorld.h b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorld.h new file mode 100644 index 00000000..aeb87bc3 --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorld.h @@ -0,0 +1,17 @@ +/*********************************************************************** +Vczh Library++ 3.0 +Developer: Zihan Chen(vczh) +GacUI::HelloWorld + +This file is generated by: Vczh GacUI Resource Code Generator +************************************************************************ +DO NOT MODIFY +***********************************************************************/ + +#ifndef VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld +#define VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld + +#include "HelloWorldPartialClasses.h" +#include "MainWindow.h" + +#endif diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.cpp b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.cpp new file mode 100644 index 00000000..238346f4 --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.cpp @@ -0,0 +1,87 @@ +/*********************************************************************** +Vczh Library++ 3.0 +Developer: Zihan Chen(vczh) +GacUI::Partial Classes + +This file is generated by: Vczh GacUI Resource Code Generator +************************************************************************ +DO NOT MODIFY +***********************************************************************/ + +#include "HelloWorld.h" + +namespace vl +{ + namespace reflection + { + namespace description + { + #define _ , + IMPL_CPP_TYPE_INFO(vm::IViewModel) + IMPL_CPP_TYPE_INFO(helloworld::MainWindow) + + BEGIN_CLASS_MEMBER(vm::IViewModel) + CLASS_MEMBER_BASE(vl::reflection::IDescriptable) + CLASS_MEMBER_METHOD(GetUserName, NO_PARAMETER); + CLASS_MEMBER_METHOD(SetUserName, { L"value" }); + CLASS_MEMBER_METHOD(GetPassword, NO_PARAMETER); + CLASS_MEMBER_METHOD(SetPassword, { L"value" }); + CLASS_MEMBER_METHOD(GetUserNameError, NO_PARAMETER); + CLASS_MEMBER_EVENT(UserNameErrorChanged) + CLASS_MEMBER_METHOD(GetPasswordError, NO_PARAMETER); + CLASS_MEMBER_EVENT(PasswordErrorChanged) + CLASS_MEMBER_METHOD(SignUp, NO_PARAMETER); + CLASS_MEMBER_PROPERTY(UserName, GetUserName, SetUserName) + CLASS_MEMBER_PROPERTY(Password, GetPassword, SetPassword) + CLASS_MEMBER_PROPERTY_EVENT_READONLY(UserNameError, GetUserNameError, UserNameErrorChanged) + CLASS_MEMBER_PROPERTY_EVENT_READONLY(PasswordError, GetPasswordError, PasswordErrorChanged) + END_CLASS_MEMBER(vm::IViewModel) + + BEGIN_CLASS_MEMBER(helloworld::MainWindow) + CLASS_MEMBER_BASE(vl::presentation::controls::GuiWindow) + CLASS_MEMBER_CONSTRUCTOR(helloworld::MainWindow*(Ptr), { L"ViewModel" }) + + CLASS_MEMBER_GUIEVENT_HANDLER(buttonSignUp_Clicked, vl::presentation::compositions::GuiEventArgs) + + CLASS_MEMBER_PROPERTY_READONLY_FAST(ViewModel) + CLASS_MEMBER_EVENT(HasLoggedInChanged) + CLASS_MEMBER_PROPERTY_EVENT_FAST(HasLoggedIn, HasLoggedInChanged) + END_CLASS_MEMBER(helloworld::MainWindow) + + #undef _ + + class HelloWorldResourceLoader : public Object, public ITypeLoader + { + public: + void Load(ITypeManager* manager) + { + ADD_TYPE_INFO(vm::IViewModel) + ADD_TYPE_INFO(helloworld::MainWindow) + } + + void Unload(ITypeManager* manager) + { + } + }; + + class HelloWorldResourcePlugin : public Object, public vl::presentation::controls::IGuiPlugin + { + public: + void Load()override + { + GetGlobalTypeManager()->AddTypeLoader(new HelloWorldResourceLoader); + } + + void AfterLoad()override + { + } + + void Unload()override + { + } + }; + GUI_REGISTER_PLUGIN(HelloWorldResourcePlugin) + } + } +} + diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.h b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.h new file mode 100644 index 00000000..c7d19eb4 --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/HelloWorldPartialClasses.h @@ -0,0 +1,119 @@ +/*********************************************************************** +Vczh Library++ 3.0 +Developer: Zihan Chen(vczh) +GacUI::Partial Classes + +This file is generated by: Vczh GacUI Resource Code Generator +************************************************************************ +DO NOT MODIFY +***********************************************************************/ + +#ifndef VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld_PARTIAL_CLASSES +#define VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld_PARTIAL_CLASSES + +#include "GacUIReflection.h" + +namespace vm +{ + class IViewModel; +} +namespace helloworld +{ + class MainWindow; + +} +namespace vm +{ + class IViewModel : public virtual vl::reflection::IDescriptable, public vl::reflection::Description + { + public: + virtual vl::WString GetUserName() = 0; + virtual void SetUserName(vl::WString value) = 0; + virtual vl::WString GetPassword() = 0; + virtual void SetPassword(vl::WString value) = 0; + virtual vl::WString GetUserNameError() = 0; + vl::Event UserNameErrorChanged; + virtual vl::WString GetPasswordError() = 0; + vl::Event PasswordErrorChanged; + virtual bool SignUp() = 0; + }; + +} +namespace helloworld +{ + template + class MainWindow_ : public vl::presentation::controls::GuiWindow, public vl::presentation::GuiInstancePartialClass, public vl::reflection::Description + { + friend struct vl::reflection::description::CustomTypeDescriptorSelector; + private: + Ptr ViewModel_; + bool HasLoggedIn_; + protected: + vl::presentation::controls::GuiButton* buttonCancel; + vl::presentation::controls::GuiButton* buttonSignUp; + vl::presentation::controls::GuiWindow* self; + vl::presentation::controls::GuiSinglelineTextBox* textBoxPassword; + vl::presentation::controls::GuiSinglelineTextBox* textBoxUserName; + + void InitializeComponents(Ptr ViewModel) + { + ViewModel_ = ViewModel; + if (InitializeFromResource()) + { + GUI_INSTANCE_REFERENCE(buttonCancel); + GUI_INSTANCE_REFERENCE(buttonSignUp); + GUI_INSTANCE_REFERENCE(self); + GUI_INSTANCE_REFERENCE(textBoxPassword); + GUI_INSTANCE_REFERENCE(textBoxUserName); + } + else + { + ViewModel_ = 0; + } + } + public: + MainWindow_() + :vl::presentation::GuiInstancePartialClass(L"helloworld::MainWindow") + ,vl::presentation::controls::GuiWindow(vl::presentation::theme::GetCurrentTheme()->CreateWindowStyle()) + ,buttonCancel(0) + ,buttonSignUp(0) + ,self(0) + ,textBoxPassword(0) + ,textBoxUserName(0) + { + } + + Ptr GetViewModel() + { + return ViewModel_; + } + + vl::Event HasLoggedInChanged; + + bool GetHasLoggedIn() + { + return HasLoggedIn_; + } + + void SetHasLoggedIn(bool value) + { + HasLoggedIn_ = value; + HasLoggedInChanged(); + } + }; + +} +namespace vl +{ + namespace reflection + { + namespace description + { + DECL_TYPE_INFO(vm::IViewModel) + DECL_TYPE_INFO(helloworld::MainWindow) + + } + } +} + +#endif diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.cpp b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.cpp new file mode 100644 index 00000000..09b3d075 --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.cpp @@ -0,0 +1,30 @@ +/*********************************************************************** +Vczh Library++ 3.0 +Developer: Zihan Chen(vczh) +GacUI::MainWindow + +This file is generated by: Vczh GacUI Resource Code Generator +***********************************************************************/ + +#include "HelloWorld.h" + +namespace helloworld +{ + // #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.) + + void MainWindow::buttonSignUp_Clicked(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments) + { + if (this->GetViewModel()->SignUp()) + { + this->SetHasLoggedIn(true); + this->buttonSignUp->SetText(L"Suggess!"); + } + } + + // #endregion CLASS_MEMBER_GUIEVENT_HANDLER + + MainWindow::MainWindow(Ptr ViewModel) + { + InitializeComponents(ViewModel); + } +} diff --git a/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.h b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.h new file mode 100644 index 00000000..2596720b --- /dev/null +++ b/Tutorial/GacUI_HelloWorlds/MVVM/UI/Source/MainWindow.h @@ -0,0 +1,30 @@ +/*********************************************************************** +Vczh Library++ 3.0 +Developer: Zihan Chen(vczh) +GacUI::MainWindow + +This file is generated by: Vczh GacUI Resource Code Generator +***********************************************************************/ + +#ifndef VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld_MainWindow +#define VCZH_GACUI_RESOURCE_CODE_GENERATOR_HelloWorld_MainWindow + +#include "HelloWorldPartialClasses.h" + +namespace helloworld +{ + class MainWindow : public helloworld::MainWindow_ + { + friend class helloworld::MainWindow_; + friend struct vl::reflection::description::CustomTypeDescriptorSelector; + protected: + + // #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.) + void buttonSignUp_Clicked(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments); + // #endregion CLASS_MEMBER_GUIEVENT_HANDLER + public: + MainWindow(Ptr ViewModel); + }; +} + +#endif diff --git a/Tutorial/GacUI_HelloWorlds/UIRes/CppXml.bin b/Tutorial/GacUI_HelloWorlds/UIRes/CppXml.bin index 035501d7..edc1a5aa 100644 Binary files a/Tutorial/GacUI_HelloWorlds/UIRes/CppXml.bin and b/Tutorial/GacUI_HelloWorlds/UIRes/CppXml.bin differ diff --git a/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin b/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin new file mode 100644 index 00000000..d6f2187e Binary files /dev/null and b/Tutorial/GacUI_HelloWorlds/UIRes/MVVM.bin differ