int App::run() { #ifdef ENABLE_UPDATER app::CheckUpdateThreadLauncher checkUpdate; #endif // Initialize GUI interface if (isGui()) { View* view; Editor* editor; PRINTF("GUI mode\n"); // Setup the GUI screen jmouse_set_cursor(JI_CURSOR_NORMAL); gui::Manager::getDefault()->invalidate(); // Load main window top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window")); box_menubar = top_window->findChild("menubar"); box_editors = top_window->findChild("editor"); box_colorbar = top_window->findChild("colorbar"); box_toolbar = top_window->findChild("toolbar"); box_statusbar = top_window->findChild("statusbar"); box_tabsbar = top_window->findChild("tabsbar"); menubar = new MenuBar(); statusbar = new StatusBar(); colorbar = new ColorBar(box_colorbar->getAlign()); toolbar = toolbar_new(); tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate()); view = new EditorView(EditorView::CurrentEditorMode); editor = create_new_editor(); // configure all widgets to expansives menubar->setExpansive(true); statusbar->setExpansive(true); colorbar->setExpansive(true); toolbar->setExpansive(true); tabsbar->setExpansive(true); view->setExpansive(true); /* prepare the first editor */ view->attachToView(editor); /* setup the menus */ menubar->setMenu(get_root_menu()); /* start text of status bar */ app_default_statusbar_message(); /* add the widgets in the boxes */ if (box_menubar) box_menubar->addChild(menubar); if (box_editors) box_editors->addChild(view); if (box_colorbar) box_colorbar->addChild(colorbar); if (box_toolbar) box_toolbar->addChild(toolbar); if (box_statusbar) box_statusbar->addChild(statusbar); if (box_tabsbar) box_tabsbar->addChild(tabsbar); /* prepare the window */ top_window->remap_window(); // Create the list of tabs app_rebuild_documents_tabs(); app_rebuild_recent_list(); // Set current editor set_current_editor(editor); // Open the window top_window->open_window(); // Redraw the whole screen. gui::Manager::getDefault()->invalidate(); } /* set background mode for non-GUI modes */ /* if (!(ase_mode & MODE_GUI)) */ /* set_display_switch_mode(SWITCH_BACKAMNESIA); */ set_display_switch_mode(SWITCH_BACKGROUND); // procress options PRINTF("Processing options...\n"); ASSERT(m_checkArgs != NULL); { Console console; for (CheckArgs::iterator it = m_checkArgs->begin(); it != m_checkArgs->end(); ++it) { CheckArgs::Option* option = *it; switch (option->type()) { case CheckArgs::Option::OpenSprite: { // Load the sprite Document* document = load_document(option->data().c_str()); if (!document) { if (!isGui()) console.printf("Error loading file \"%s\"\n", option->data().c_str()); } else { // Mount and select the sprite UIContext* context = UIContext::instance(); context->addDocument(document); context->setActiveDocument(document); if (isGui()) { // Show it set_document_in_more_reliable_editor(context->getFirstDocument()); // Recent file getRecentFiles()->addRecentFile(option->data().c_str()); } } break; } } } delete m_checkArgs; m_checkArgs = NULL; } // Run the GUI if (isGui()) { // Support to drop files from Windows explorer install_drop_files(); #ifdef ENABLE_UPDATER // Launch the thread to check for updates. checkUpdate.launch(); #endif // Run the GUI main message loop gui_run(); // Uninstall support to drop files uninstall_drop_files(); // Remove the root-menu from the menu-bar (because the rootmenu // module should destroy it). menubar->setMenu(NULL); // Delete all editors first because they used signals from other // widgets (e.g. color bar). delete box_editors; // Destroy mini-editor. exit_module_editors(); // Destroy the top-window delete top_window; top_window = NULL; } return 0; }
bool StandbyState::onMouseDown(Editor* editor, Message* msg) { if (editor->hasCapture()) return true; UIContext* context = UIContext::instance(); tools::Tool* current_tool = editor->getCurrentEditorTool(); Sprite* sprite = editor->getSprite(); // Each time an editor is clicked the current editor and the active // document are set. set_current_editor(editor); context->setActiveDocument(editor->getDocument()); // Start scroll loop if (msg->mouse.middle || current_tool->getInk(msg->mouse.right ? 1: 0)->isScrollMovement()) { editor->setState(EditorStatePtr(new ScrollingState())); editor->captureMouse(); return true; } // Move frames position if (current_tool->getInk(msg->mouse.right ? 1: 0)->isCelMovement()) { if ((sprite->getCurrentLayer()) && (sprite->getCurrentLayer()->getType() == GFXOBJ_LAYER_IMAGE)) { // TODO you can move the `Background' with tiled mode if (sprite->getCurrentLayer()->is_background()) { Alert::show(PACKAGE "<<You can't move the `Background' layer." "||&Close"); } else if (!sprite->getCurrentLayer()->is_moveable()) { Alert::show(PACKAGE "<<The layer movement is locked.||&Close"); } else { bool click2 = get_config_bool("Options", "MoveClick2", FALSE); // TODO replace "interactive_move_layer" with a new EditorState interactive_move_layer(click2 ? Editor::MODE_CLICKANDCLICK: Editor::MODE_CLICKANDRELEASE, TRUE, NULL); } } } // Move selected pixels else if (editor->isInsideSelection() && current_tool->getInk(0)->isSelection() && msg->mouse.left) { int x, y, opacity; Image* image = sprite->getCurrentImage(&x, &y, &opacity); if (image) { if (!sprite->getCurrentLayer()->is_writable()) { Alert::show(PACKAGE "<<The layer is locked.||&Close"); return true; } // Change to MovingPixelsState editor->setState(EditorStatePtr(new MovingPixelsState(editor, msg, image, x, y, opacity))); } } // Call the eyedropper command else if (current_tool->getInk(msg->mouse.right ? 1: 0)->isEyedropper()) { Command* eyedropper_cmd = CommandsModule::instance()->getCommandByName(CommandId::Eyedropper); Params params; params.set("target", msg->mouse.right ? "background": "foreground"); UIContext::instance()->executeCommand(eyedropper_cmd, ¶ms); return true; } // Start the Tool-Loop else if (sprite->getCurrentLayer()) { tools::ToolLoop* toolLoop = create_tool_loop(editor, context, msg); if (toolLoop) editor->setState(EditorStatePtr(new DrawingState(toolLoop, editor, msg))); } return true; }