a.koryakin Posted November 26, 2014 Share Posted November 26, 2014 I creating my own widget and want to inherit it from base widget class like this : class ProgressBarWidget : Widget { ProgressBarWidget(Gui gui, string name): Widget(gui, name) { ....something....} };calling in other script ....ProgressBarWidget pbar = new ProgressBarWidget(); gui.addChild(pbar.extern, GUI_ALIGN_CENTER);....and i have the following message Is there some sintaxis error? Link to comment
silent Posted November 26, 2014 Share Posted November 26, 2014 Hi, Could you please provide a full source code? This would help a lot. Also, you can try to run engine with debug binaries to get more detailed errors in console. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
a.koryakin Posted November 27, 2014 Author Share Posted November 27, 2014 here i have the example codeEmpty.rar Link to comment
silent Posted November 27, 2014 Share Posted November 27, 2014 Hi, There is no easy way to inherit from base class. Could you please try to inherit from Unigine::Widgets. For example, using this code: #include <core/systems/widgets/widget.h> using Unigine::Widgets; class ProgressBarWidget : Widget { int width = 150; ProgressBarWidget(int w) { __Widget__(w); } ~ProgressBarWidget() { __Widget__(); } }; Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
a.koryakin Posted November 28, 2014 Author Share Posted November 28, 2014 hi, i did what you said byt it still not working.Empty.rar Link to comment
unclebob Posted November 28, 2014 Share Posted November 28, 2014 Actually, you have a lot of options here: 1) Inherit from WidgetExternBase. That way you'll be able to create your custom widget from C++ side as well as from the script. 2) Don't use inheritance at all and use WidgetCanvas instead to draw custom graphics and event handling. So your custom widget will be a wrapper class over WidgetCanvas. 3) Inherit from Unigine::Widgets::Widget class in the script as it has support for both multi- and single window modes. That's the way silent had suggested you. By the way, I've modified your code so it's working now. Please find it in the attachments. Have a good weekend! Empty.zip Link to comment
a.koryakin Posted November 29, 2014 Author Share Posted November 29, 2014 Thank you very much!it works great, I'll use 3'rd way.I need to drow some custom texture inside widget with local (relatively to container coordinates), i think WidgetCanvas cant do this.WidgetExternBase is ok but all GUI part of my application is already in scripts now, its bad to separate my code, and put widgets to c++ code. Link to comment
a.koryakin Posted November 29, 2014 Author Share Posted November 29, 2014 I still have trouble adding my custom ProgressBarWidget widget to ObjectGui. ObjectGui object_gui = add_editor(new ObjectGui(30.0f, 30.0f)); object_gui.setPosition(dvec3(0, 0, 10 + 15)); object_gui.setBillboard(1); object_gui.setBackground(0); object_gui.setMaterial("gui_base","*"); object_gui.setProperty("surface_base","*"); object_gui.setScreenSize(300, 300); object_gui.setControlDistance(100000.0f); Gui gui = object_gui.getGui(); ProgressBarWidget pbw = new ProgressBarWidget(10, gui); pbw.stop(); WidgetVBox allContainer = new WidgetVBox(gui); allContainer.addChild(pbw); gui.addChild(allContainer, GUI_ALIGN_CENTER);Empty.rarI got this messagethere is no trouble when i add widget:addChild(pbw,ALIGN_CENTER); Link to comment
unclebob Posted December 2, 2014 Share Posted December 2, 2014 That's because Unigine::Widgets::Widget script class is not inherited from C++ Widget class, it's a wrapper. That said, it won't work with gui.addChild method that way yet there're few ways to solve this. You can either access its inner field ProgressBarWidget pbw = new ProgressBarWidget(10,gui); gui.addChild(pbw.widget, GUI_ALIGN_EXPAND); or just use addChild method. Link to comment
a.koryakin Posted December 2, 2014 Author Share Posted December 2, 2014 method gui.addChild(pbw.widget, GUI_ALIGN_EXPAND); works wellThis is working test user widget Empty.rarProblem solved, thank you. Link to comment
Recommended Posts