X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fdialog.cpp;h=0323161b4dcb32682ef048502972a17926c7d4f2;hb=8705acc09238c97ba0e79094621f0d6c859a7eb1;hp=ff215079610f2fbf31b2d3aadcffba36e737a405;hpb=fea0d2e6575b21945c4800805d66e43a2247ded5;p=xonotic%2Fnetradiant.git diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index ff215079..0323161b 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -108,141 +108,139 @@ DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lo struct BoolToggle { - static void Export(const GtkToggleButton &self, const Callback &returnz) { - returnz(gtk_toggle_button_get_active(const_cast(&self)) != FALSE); + static void Export(const ui::ToggleButton &self, const Callback &returnz) { + returnz(self.active()); } - static void Import(GtkToggleButton &self, bool value) { - gtk_toggle_button_set_active(&self, value); + static void Import(ui::ToggleButton &self, bool value) { + self.active(value); } }; -using BoolToggleImportExport = PropertyAdaptor; +using BoolToggleImportExport = PropertyAdaptor; struct IntEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz(atoi(gtk_entry_get_text(const_cast(&self)))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(atoi(gtk_entry_get_text(self))); } - static void Import(GtkEntry &self, int value) { - entry_set_int(ui::Entry(&self), value); + static void Import(ui::Entry &self, int value) { + entry_set_int(self, value); } }; -using IntEntryImportExport = PropertyAdaptor; +using IntEntryImportExport = PropertyAdaptor; struct IntRadio { - static void Export(const GtkRadioButton &self, const Callback &returnz) { - returnz(radio_button_get_active(ui::RadioButton(const_cast(&self)))); + static void Export(const ui::RadioButton &self, const Callback &returnz) { + returnz(radio_button_get_active(self)); } - static void Import(GtkRadioButton &self, int value) { - radio_button_set_active(ui::RadioButton(&self), value); + static void Import(ui::RadioButton &self, int value) { + radio_button_set_active(self, value); } }; -using IntRadioImportExport = PropertyAdaptor; +using IntRadioImportExport = PropertyAdaptor; struct IntCombo { - static void Export(const GtkComboBox &self, const Callback &returnz) { - returnz(gtk_combo_box_get_active(const_cast(&self))); + static void Export(const ui::ComboBox &self, const Callback &returnz) { + returnz(gtk_combo_box_get_active(self)); } - static void Import(GtkComboBox &self, int value) { - gtk_combo_box_set_active(&self, value); + static void Import(ui::ComboBox &self, int value) { + gtk_combo_box_set_active(self, value); } }; -using IntComboImportExport = PropertyAdaptor; +using IntComboImportExport = PropertyAdaptor; struct IntAdjustment { - static void Export(const GtkAdjustment &self, const Callback &returnz) { - returnz((int) gtk_adjustment_get_value(const_cast(&self))); + static void Export(const ui::Adjustment &self, const Callback &returnz) { + returnz(int(gtk_adjustment_get_value(self))); } - static void Import(GtkAdjustment &self, int value) { - gtk_adjustment_set_value(&self, value); + static void Import(ui::Adjustment &self, int value) { + gtk_adjustment_set_value(self, value); } }; -using IntAdjustmentImportExport = PropertyAdaptor; +using IntAdjustmentImportExport = PropertyAdaptor; struct IntSpinner { - static void Export(const GtkSpinButton &self, const Callback &returnz) { - returnz(gtk_spin_button_get_value_as_int(const_cast(&self))); + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(gtk_spin_button_get_value_as_int(self)); } - static void Import(GtkSpinButton &self, int value) { - gtk_spin_button_set_value(&self, value); + static void Import(ui::SpinButton &self, int value) { + gtk_spin_button_set_value(self, value); } }; -using IntSpinnerImportExport = PropertyAdaptor; - -using StringImportExport = PropertyAdaptor; +using IntSpinnerImportExport = PropertyAdaptor; struct TextEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz(gtk_entry_get_text(const_cast(&self))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(gtk_entry_get_text(self)); } - static void Import(GtkEntry &self, const char *value) { - ui::Entry(&self).text(value); + static void Import(ui::Entry &self, const char *value) { + self.text(value); } }; -using TextEntryImportExport = PropertyAdaptor; +using TextEntryImportExport = PropertyAdaptor; struct SizeEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - int value = atoi(gtk_entry_get_text(const_cast(&self))); + static void Export(const ui::Entry &self, const Callback &returnz) { + int value = atoi(gtk_entry_get_text(self)); if (value < 0) { value = 0; } returnz(value); } - static void Import(GtkEntry &self, std::size_t value) { - entry_set_int(ui::Entry(&self), int(value)); + static void Import(ui::Entry &self, std::size_t value) { + entry_set_int(self, int(value)); } }; -using SizeEntryImportExport = PropertyAdaptor; +using SizeEntryImportExport = PropertyAdaptor; struct FloatEntry { - static void Export(const GtkEntry &self, const Callback &returnz) { - returnz((float) atof(gtk_entry_get_text(const_cast(&self)))); + static void Export(const ui::Entry &self, const Callback &returnz) { + returnz(float(atof(gtk_entry_get_text(self)))); } - static void Import(GtkEntry &self, float value) { - entry_set_float(ui::Entry(&self), value); + static void Import(ui::Entry &self, float value) { + entry_set_float(self, value); } }; -using FloatEntryImportExport = PropertyAdaptor; +using FloatEntryImportExport = PropertyAdaptor; struct FloatSpinner { - static void Export(const GtkSpinButton &self, const Callback &returnz) { - returnz(float(gtk_spin_button_get_value(const_cast(&self)))); + static void Export(const ui::SpinButton &self, const Callback &returnz) { + returnz(float(gtk_spin_button_get_value(self))); } - static void Import(GtkSpinButton &self, float value) { - gtk_spin_button_set_value(&self, value); + static void Import(ui::SpinButton &self, float value) { + gtk_spin_button_set_value(self, value); } }; -using FloatSpinnerImportExport = PropertyAdaptor; +using FloatSpinnerImportExport = PropertyAdaptor; template class CallbackDialogData : public DLG_DATA { - Property m_cbWidget; - Property m_cbViewer; + Property m_pWidget; + Property m_pData; public: - CallbackDialogData(const Property &cbWidget, const Property &cbViewer) - : m_cbWidget(cbWidget), m_cbViewer(cbViewer) { + CallbackDialogData(const Property &pWidget, const Property &pData) + : m_pWidget(pWidget), m_pData(pData) { } void release() { @@ -250,42 +248,51 @@ public: } void importData() const { - m_cbViewer.get(m_cbWidget.set); + m_pData.get(m_pWidget.set); } void exportData() const { - m_cbWidget.get(m_cbViewer.set); + m_pWidget.get(m_pData.set); } }; -template -void AddData(DialogDataList &data, typename Widget::Type &widget, typename Viewer::Type &viewer) { - data.push_back( - new CallbackDialogData( - make_property(widget), - make_property(viewer) - ) - ); -} - -template -void AddCustomData( - DialogDataList &data, - typename Widget::Type &widget, - Property const &cbViewer -) { - data.push_back( - new CallbackDialogData( - make_property(widget), - cbViewer - ) - ); +template +struct AddDataCustom_Wrapper { + static void Export(const native &self, const Callback &returnz) { + native *p = &const_cast(self); + auto widget = Self::from(p); + Widget::Get::thunk_(widget, returnz); + } + + static void Import(native &self, T value) { + native *p = &self; + auto widget = Self::from(p); + Widget::Set::thunk_(widget, value); + } +}; + +template +void AddDataCustom(DialogDataList &self, typename Widget::Type widget, Property const &property) { + using Self = typename Widget::Type; + using T = typename Widget::Other; + using native = typename std::remove_pointer::type; + using Wrapper = AddDataCustom_Wrapper; + + self.push_back(new CallbackDialogData( + make_property>(*static_cast(widget)), + property + )); +} + +template +void AddData(DialogDataList &self, typename Widget::Type widget, D &data) { + AddDataCustom(self, widget, make_property>(data)); } // ============================================================================= // Dialog class -Dialog::Dialog() : m_window( 0 ), m_parent( 0 ){ +Dialog::Dialog() : m_window( ui::null ), m_parent( ui::null ){ } Dialog::~Dialog(){ @@ -330,76 +337,76 @@ void Dialog::Destroy(){ } -void Dialog::AddBoolToggleData( GtkToggleButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddBoolToggleData( ui::ToggleButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntRadioData( GtkRadioButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntRadioData( ui::RadioButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddTextEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddTextEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddSizeEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddSizeEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatEntryData( GtkEntry& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddFloatEntryData( ui::Entry widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddFloatSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntSpinnerData( GtkSpinButton& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntSpinnerData( ui::SpinButton widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntAdjustmentData( ui::Adjustment widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddIntComboData( GtkComboBox& widget, Property const &cb ){ - AddCustomData( m_data, widget, cb ); +void Dialog::AddIntComboData( ui::ComboBox widget, Property const &cb ){ + AddDataCustom( m_data, widget, cb ); } -void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::ToggleButton widget, bool& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkRadioButton& widget, int& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::RadioButton widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, CopiedString& data ){ - AddData( m_data, widget, data ); +void Dialog::AddDialogData( ui::Entry widget, CopiedString& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, int& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::Entry widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, std::size_t& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::Entry widget, std::size_t& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkEntry& widget, float& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::Entry widget, float& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkSpinButton& widget, float& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::SpinButton widget, float& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkSpinButton& widget, int& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::SpinButton widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkAdjustment& widget, int& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::Adjustment widget, int& data ){ + AddData( m_data, widget, data ); } -void Dialog::AddDialogData( GtkComboBox& widget, int& data ){ - AddData>( m_data, widget, data ); +void Dialog::AddDialogData( ui::ComboBox widget, int& data ){ + AddData( m_data, widget, data ); } void Dialog::exportData(){ @@ -439,11 +446,28 @@ EMessageBoxReturn Dialog::DoModal(){ return m_modal.ret; } +ui::VBox Dialog::addSpacer( ui::VBox vbox, int dimension ){ + auto spacer = ui::VBox( FALSE, 0 ); + gtk_widget_set_size_request( GTK_WIDGET( spacer ), dimension, dimension ); + spacer.show(); + + DialogVBox_packRow( vbox, spacer ); + return spacer; +} + +ui::Label Dialog::addLabel( ui::VBox vbox, const char* name, const char* text ){ + auto label = ui::Label( text ); + gtk_misc_set_alignment( GTK_MISC( label ), 0.0, 0.5 ); + label.show(); + + DialogVBox_packRow( vbox, ui::Widget(DialogRow_new( name, label ) )); + return label; +} ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, Property const &cb ){ auto check = ui::CheckButton( flag ); check.show(); - AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), cb ); + AddBoolToggleData( check, cb ); DialogVBox_packRow( vbox, ui::Widget(DialogRow_new( name, check ) )); return check; @@ -464,7 +488,7 @@ void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), *i ); } - AddIntComboData( *GTK_COMBO_BOX( combo ), cb ); + AddIntComboData( combo, cb ); combo.show(); alignment.add(combo); @@ -499,7 +523,7 @@ void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean dra // adjustment auto adj = ui::Adjustment( value, lower, upper, step_increment, page_increment, 0 ); - AddIntAdjustmentData(*GTK_ADJUSTMENT(adj), make_property(data)); + AddIntAdjustmentData(adj, make_property(data)); // scale auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 ); @@ -523,7 +547,7 @@ void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, { RadioHBox radioBox = RadioHBox_new( names ); alignment.add(radioBox.m_hbox); - AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), cb ); + AddIntRadioData( radioBox.m_radio, cb ); } auto row = DialogRow_new( name, alignment ); @@ -550,14 +574,14 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange ic image.show(); table.attach(image, {pos, pos + 1, 0, 1}, {0, 0}); - radio = ui::RadioButton(GTK_RADIO_BUTTON(gtk_radio_button_new( group ))); + radio = ui::RadioButton::from(gtk_radio_button_new( group )); radio.show(); table.attach(radio, {pos, pos + 1, 1, 2}, {0, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( radio ) ); } - AddIntRadioData( *GTK_RADIO_BUTTON( radio ), cb ); + AddIntRadioData( radio, cb ); DialogVBox_packRow( vbox, DialogRow_new( name, table ) ); } @@ -568,21 +592,21 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, int& data, StringAr ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddIntEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddIntEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddSizeEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddSizeEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddFloatEntryData( *GTK_ENTRY(row.m_entry), cb ); + AddFloatEntryData( row.m_entry, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } @@ -591,7 +615,7 @@ ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_di PathEntry pathEntry = PathEntry_new(); pathEntry.m_button.connect( "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry ); - AddTextEntryData( *GTK_ENTRY(pathEntry.m_entry), cb ); + AddTextEntryData( pathEntry.m_entry, cb ); auto row = DialogRow_new( name, ui::Widget(pathEntry.m_frame ) ); DialogVBox_packRow( vbox, row ); @@ -605,7 +629,7 @@ ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, CopiedString& ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) ); - AddIntSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); + AddIntSpinnerData( row.m_spin, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_spin; } @@ -616,7 +640,7 @@ ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, int& data, d ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) ); - AddFloatSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); + AddFloatSpinnerData( row.m_spin, cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_spin; }