void visit(const char* name, Accelerator& accelerator) { StringOutputStream modifiers; modifiers << accelerator; { GtkTreeIter iter; gtk_list_store_append(m_store, &iter); gtk_list_store_set(m_store, &iter, 0, name, 1, modifiers.c_str(), -1); } if(!m_commandList.failed()) { m_commandList << makeLeftJustified(name, 25) << " " << modifiers.c_str() << '\n'; } }
void visit( const char* name, Accelerator& accelerator ){ StringOutputStream modifiers; modifiers << accelerator; { GtkTreeIter iter; gtk_list_store_append( m_store, &iter ); gtk_list_store_set( m_store, &iter, 0, name, 1, modifiers.c_str(), 2, false, 3, 800, -1 ); } if ( !m_commandList.failed() ) { int l = strlen( name ); m_commandList << name; while ( l++ < 25 ) m_commandList << ' '; m_commandList << modifiers.c_str() << '\n'; } }
void Scene_EntitySetClassname_Selected( const char* classname ){ if ( GlobalSelectionSystem().countSelected() > 0 ) { StringOutputStream command; if( string_equal( classname, "worldspawn" ) ) command << "ungroupSelectedEntities"; else command << "entitySetClass -class " << classname; UndoableCommand undo( command.c_str() ); GlobalSceneGraph().traverse( EntitySetClassnameSelected( classname ) ); } }
void Brush_ConstructPrefab(Brush& brush, EBrushPrefab type, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection) { switch(type) { case eBrushCuboid: { UndoableCommand undo("brushCuboid"); Brush_ConstructCuboid(brush, bounds, shader, projection); } break; case eBrushPrism: { int axis = GetViewAxis(); StringOutputStream command; command << c_brushPrism_name << " -sides " << Unsigned(sides) << " -axis " << axis; UndoableCommand undo(command.c_str()); Brush_ConstructPrism(brush, bounds, sides, axis, shader, projection); } break; case eBrushCone: { StringOutputStream command; command << c_brushCone_name << " -sides " << Unsigned(sides); UndoableCommand undo(command.c_str()); Brush_ConstructCone(brush, bounds, sides, shader, projection); } break; case eBrushSphere: { StringOutputStream command; command << c_brushSphere_name << " -sides " << Unsigned(sides); UndoableCommand undo(command.c_str()); Brush_ConstructSphere(brush, bounds, sides, shader, projection); } break; } }
void Sys_SetTitle(const char *text, bool modified) { StringOutputStream title; title << ConvertLocaleToUTF8(text); if(modified) { title << " *"; } gtk_window_set_title(MainFrame_getWindow(), title.c_str()); }
void CPointfile::saxEndElement (message_info_t *ctx, const xmlChar *name) { if(string_equal(reinterpret_cast<const char*>(name), "polyline")) { // we are done GenerateDisplayList(); SceneChangeNotify(); } else if(string_equal(reinterpret_cast<const char*>(name), "point")) { Vector3 v; sscanf(m_characters.c_str(), "%f %f %f\n", &v[0], &v[1], &v[2]); PushPoint(v); m_characters.clear(); } }
/// moves selected primitives to entity, which is or its primitive is ultimateSelected() or firstSelected() void Entity_moveSelectedPrimitives( bool toLast ){ if ( GlobalSelectionSystem().countSelected() < 2 ) { globalErrorStream() << "Source and target entity primitives should be selected!\n"; return; } const scene::Path& path = toLast? GlobalSelectionSystem().ultimateSelected().path() : GlobalSelectionSystem().firstSelected().path(); scene::Node& node = ( !Node_isEntity( path.top() ) && path.size() > 1 )? path.parent() : path.top(); if ( Node_isEntity( node ) && node_is_group( node ) ) { StringOutputStream command; command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getEntityClass().name() ); UndoableCommand undo( command.c_str() ); Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); } }
void visit( const char* name, Accelerator& accelerator ){ if ( !strcmp( name, commandName ) ) { return; } if ( !allow ) { return; } if ( accelerator.key == 0 ) { return; } if ( accelerator == newAccel ) { StringOutputStream msg; msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n" << "Do you want to unassign " << name << " first?"; EMessageBoxReturn r = gtk_MessageBox( widget, msg.c_str(), "Key already used", eMB_YESNOCANCEL ); if ( r == eIDYES ) { // clear the ACTUAL accelerator too! disconnect_accelerator( name ); // delete the modifier accelerator = accelerator_null(); // empty the cell of the key binds dialog GtkTreeIter i; if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL( model ), &i ) ) { for (;; ) { GValue val; memset( &val, 0, sizeof( val ) ); gtk_tree_model_get_value( GTK_TREE_MODEL( model ), &i, 0, &val ); const char *thisName = g_value_get_string( &val );; if ( !strcmp( thisName, name ) ) { gtk_list_store_set( GTK_LIST_STORE( model ), &i, 1, "", -1 ); } g_value_unset( &val ); if ( !gtk_tree_model_iter_next( GTK_TREE_MODEL( model ), &i ) ) { break; } } } } else if ( r == eIDCANCEL ) { // aborted allow = false; } } }
gboolean accelerator_window_key_press( GtkWidget *widget, GdkEventKey *event, gpointer dialogptr ){ command_list_dialog_t &dialog = *(command_list_dialog_t *) dialogptr; if ( !dialog.m_waiting_for_key ) { return false; } #if 0 if ( event->is_modifier ) { return false; } #else switch ( event->keyval ) { case GDK_Shift_L: case GDK_Shift_R: case GDK_Control_L: case GDK_Control_R: case GDK_Caps_Lock: case GDK_Shift_Lock: case GDK_Meta_L: case GDK_Meta_R: case GDK_Alt_L: case GDK_Alt_R: case GDK_Super_L: case GDK_Super_R: case GDK_Hyper_L: case GDK_Hyper_R: return false; } #endif dialog.m_waiting_for_key = false; // 7. find the name of the accelerator GValue val; memset( &val, 0, sizeof( val ) ); gtk_tree_model_get_value( GTK_TREE_MODEL( dialog.m_model ), &dialog.m_command_iter, 0, &val ); const char *commandName = g_value_get_string( &val );; Shortcuts::iterator thisShortcutIterator = g_shortcuts.find( commandName ); if ( thisShortcutIterator == g_shortcuts.end() ) { gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 ); gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true ); return true; } // 8. build an Accelerator Accelerator newAccel( event->keyval, (GdkModifierType) event->state ); // 8. verify the key is still free, show a dialog to ask what to do if not class VerifyAcceleratorNotTaken : public CommandVisitor { const char *commandName; const Accelerator &newAccel; GtkWidget *widget; GtkTreeModel *model; public: bool allow; VerifyAcceleratorNotTaken( const char *name, const Accelerator &accelerator, GtkWidget *w, GtkTreeModel *m ) : commandName( name ), newAccel( accelerator ), widget( w ), model( m ), allow( true ){ } void visit( const char* name, Accelerator& accelerator ){ if ( !strcmp( name, commandName ) ) { return; } if ( !allow ) { return; } if ( accelerator.key == 0 ) { return; } if ( accelerator == newAccel ) { StringOutputStream msg; msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n" << "Do you want to unassign " << name << " first?"; EMessageBoxReturn r = gtk_MessageBox( widget, msg.c_str(), "Key already used", eMB_YESNOCANCEL ); if ( r == eIDYES ) { // clear the ACTUAL accelerator too! disconnect_accelerator( name ); // delete the modifier accelerator = accelerator_null(); // empty the cell of the key binds dialog GtkTreeIter i; if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL( model ), &i ) ) { for (;; ) { GValue val; memset( &val, 0, sizeof( val ) ); gtk_tree_model_get_value( GTK_TREE_MODEL( model ), &i, 0, &val ); const char *thisName = g_value_get_string( &val );; if ( !strcmp( thisName, name ) ) { gtk_list_store_set( GTK_LIST_STORE( model ), &i, 1, "", -1 ); } g_value_unset( &val ); if ( !gtk_tree_model_iter_next( GTK_TREE_MODEL( model ), &i ) ) { break; } } } } else if ( r == eIDCANCEL ) { // aborted allow = false; } } } } verify_visitor( commandName, newAccel, widget, dialog.m_model ); GlobalShortcuts_foreach( verify_visitor ); gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 ); gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true ); if ( verify_visitor.allow ) { // clear the ACTUAL accelerator first disconnect_accelerator( commandName ); thisShortcutIterator->second.first = newAccel; // write into the cell StringOutputStream modifiers; modifiers << newAccel; gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 1, modifiers.c_str(), -1 ); // set the ACTUAL accelerator too! connect_accelerator( commandName ); } g_value_unset( &val ); dialog.m_model = NULL; return true; }
void Entity_createFromSelection( const char* name, const Vector3& origin ){ #if 0 if ( string_equal_nocase( name, "worldspawn" ) ) { gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "Can't create an entity with worldspawn.", "info" ); return; } #else const scene::Node* world_node = Map_FindWorldspawn( g_map ); if ( world_node && string_equal( name, "worldspawn" ) ) { // GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!", "Info", eMB_OK, eMB_ICONDEFAULT ); UndoableCommand undo( "ungroupSelectedPrimitives" ); Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), Map_FindOrInsertWorldspawn( g_map ) ); //=no action, if no worldspawn (but one inserted) (since insertion deselects everything) //Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), *Map_FindWorldspawn( g_map ) ); = crash, if no worldspawn return; } #endif StringOutputStream command; command << "entityCreate -class " << name; UndoableCommand undo( command.c_str() ); EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( name, true ); const bool isModel = entityClass->miscmodel_is || ( GlobalSelectionSystem().countSelected() == 0 && classname_equal( name, "func_static" ) && g_pGameDescription->mGameType == "doom3" ); const bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0; //is important to have retexturing here; if doing in the end, undo doesn't succeed; if ( string_compare_nocase_n( name, "trigger_", 8 ) == 0 && brushesSelected && !entityClass->fixedsize ){ //const char* shader = GetCommonShader( "trigger" ).c_str(); Scene_PatchSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() ); Scene_BrushSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() ); } if ( !( entityClass->fixedsize || isModel ) && !brushesSelected ) { globalErrorStream() << "failed to create a group entity - no brushes are selected\n"; return; } AABB workzone( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) ); Node_getTraversable( GlobalSceneGraph().root() )->insert( node ); scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) ); entitypath.push( makeReference( node.get() ) ); scene::Instance& instance = findInstance( entitypath ); if ( entityClass->fixedsize || ( isModel && !brushesSelected ) ) { //Select_Delete(); Transformable* transform = Instance_getTransformable( instance ); if ( transform != 0 ) { transform->setType( TRANSFORM_PRIMITIVE ); transform->setTranslation( origin ); transform->freezeTransform(); } GlobalSelectionSystem().setSelectedAll( false ); Instance_setSelected( instance, true ); } else { if ( g_pGameDescription->mGameType == "doom3" ) { Node_getEntity( node )->setKeyValue( "model", Node_getEntity( node )->getKeyValue( "name" ) ); } Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); Scene_forEachChildSelectable( SelectableSetSelected( true ), instance.path() ); } // tweaking: when right click dropping a light entity, ask for light value in a custom dialog box // see SF bug 105383 if ( g_pGameDescription->mGameType == "hl" ) { // FIXME - Hydra: really we need a combined light AND color dialog for halflife. if ( string_equal_nocase( name, "light" ) || string_equal_nocase( name, "light_environment" ) || string_equal_nocase( name, "light_spot" ) ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[30]; sprintf( buf, "255 255 255 %d", intensity ); Node_getEntity( node )->setKeyValue( "_light", buf ); } } } else if ( string_equal_nocase( name, "light" ) ) { if ( g_pGameDescription->mGameType != "doom3" ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[10]; sprintf( buf, "%d", intensity ); Node_getEntity( node )->setKeyValue( "light", buf ); } } else if ( brushesSelected ) { // use workzone to set light position/size for doom3 lights, if there are brushes selected AABB bounds( Doom3Light_getBounds( workzone ) ); StringOutputStream key( 64 ); key << bounds.origin[0] << " " << bounds.origin[1] << " " << bounds.origin[2]; Node_getEntity( node )->setKeyValue( "origin", key.c_str() ); key.clear(); key << bounds.extents[0] << " " << bounds.extents[1] << " " << bounds.extents[2]; Node_getEntity( node )->setKeyValue( "light_radius", key.c_str() ); } } if ( isModel ) { const char* model = misc_model_dialog( GTK_WIDGET( MainFrame_getWindow() ) ); if ( model != 0 ) { Node_getEntity( node )->setKeyValue( entityClass->miscmodel_key() , model ); } } }