Jump to content

Parent for system dialogs.


photo

Recommended Posts

Hi all,

In our application, Unigine window covers two monitors, the problem in when you show a widget centered, like DialogMessages, it appears in the middle of the screens and it's a little bit annoying.

A generic and intuitive solution is to add a new parameter to show() method called parent (default value is NULL).

By default it works as always being the dialog window child of engine.gui, but if you optionally pass a valid widget reference, the dialog is centered to that parent widget.

 

This is the implementation for DialogMessage:


/* message dialog
*/
namespace DialogMessage {
   // ...

   /* show dialog modal and return result
   */
   int show(string title,string message,int button_flags,Widget parent=NULL) {

   	// init gui
       init();
       window.setText(title);
       label.setText(message);

       // generate buttons by given flags
       foreachkey(int b; button_names) {
           if(b & button_flags) {
           WidgetButton button = new WidgetButton(gui,button_names[b]);
           if(button_images[b] != "") button.setImage(new Image(button_images[b]));
           	button.setCallback(GUI_CLICKED,"DialogMessage::button_clicked",:huh:;
     	  	hbox.addChild(button);
	           buttons.append(button);
           }
       }

       window.arrange();

       // enter hotkey for first button and Esc for last
       buttons[0].setCallbackAccel(GUI_CLICKED,APP_KEY_RETURN,0,0,0);
       buttons[buttons.size() - 1].setCallbackAccel(GUI_CLICKED,APP_KEY_ESC,0,0,0);

       // show window
       if(parent == NULL) {
           gui.addChild(window,GUI_ALIGN_OVERLAP | GUI_ALIGN_CENTER);
       }
       else {
           parent.addChild(window, GUI_ALIGN_OVERLAP);
       	window.setPosition((parent.getWidth() - window.getWidth())/2,(parent.getHeight() - window.getHeight())/2);
       }
       window.setPermanentFocus();

       // wait until user close dialog
       dialog_result = -1;
       while(dialog_result < 0) wait 1;

       // close window
       if(parent == NULL)
           gui.removeChild(window);
       else
       	parent.removeChild(window);

       shutdown();

       return dialog_result;
   }

   // ...
}

Link to comment
×
×
  • Create New...