void load_tab(unsigned char tab) { struct widget_config *w_cfg = &config.widgets[0]; struct widget *w; struct widget_config tmp_wcfg; struct widget **aw = active_widgets; DTABS("Loading tab %d\n", tab); /* stop rendering */ video_pause(); while ((*aw) != NULL) { if ((*aw)->ops->close != NULL) { DTABS("closing widget %p: %s\n", *aw, (*aw)->ops->name); (*aw)->ops->close(*aw); } aw++; } aw = active_widgets; /* reset widgets module */ widgets_reset(); if (tab == 0) { /* zero tab */ /* console */ tmp_wcfg.widget_id = WIDGET_CONSOLE_ID; tmp_wcfg.x = 0; tmp_wcfg.y = 0; tmp_wcfg.props.vjust = VJUST_TOP; tmp_wcfg.props.hjust = HJUST_LEFT; w = load_widget(&tmp_wcfg); tmp_wcfg.widget_id = WIDGET_VIDEOLVL_ID; tmp_wcfg.props.hjust = HJUST_RIGHT; w = load_widget(&tmp_wcfg); } else { /* load tab widgets */ while (w_cfg->tab != TABS_END) { if (w_cfg->tab == tab) { w = load_widget(w_cfg); if (w == NULL) break; *(aw++) = w; } w_cfg++; } } *aw = NULL; /* resume video rendering */ video_resume(); active_tab = tab; DTABS("Loaded\n"); }
shared_ptr<widget> make_widget(int id) { static map<int, weak_ptr<widget>> cache; static mutex mut_cache; lock_guard<mutex> hold(mut_cache); auto sp = cache[id].lock(); if (!sp) cache[id] = sp = load_widget(id); return sp; }
void NewLayerSetCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite(document->getSprite()); // load the window widget FramePtr window(load_widget("new_layer.xml", "new_layer_set")); window->open_window_fg(); if (window->get_killer() == window->findChild("ok")) { const char *name = window->findChild("name")->getText(); Layer* layer = new LayerFolder(sprite); layer->setName(name); sprite->getFolder()->add_layer(layer); sprite->setCurrentLayer(layer); update_screen_for_document(document); } }
void NewLayerCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite(document->getSprite()); std::string name; // Default name (m_name is a name specified in params) if (!m_name.empty()) name = m_name; else name = get_unique_layer_name(sprite); // If params specify to ask the user about the name... if (m_ask) { // We open the window to ask the name FramePtr window(load_widget("new_layer.xml", "new_layer")); JWidget name_widget = find_widget(window, "name"); name_widget->setText(name.c_str()); jwidget_set_min_size(name_widget, 128, 0); window->open_window_fg(); if (window->get_killer() != window->findChild("ok")) return; name = window->findChild("name")->getText(); } Layer* layer; { UndoTransaction undoTransaction(document, "New Layer"); layer = undoTransaction.newLayer(); undoTransaction.commit(); } layer->setName(name); update_screen_for_document(document); app_get_statusbar()->invalidate(); app_get_statusbar()->showTip(1000, "Layer `%s' created", name.c_str()); }
// Shows the JPEG configuration dialog. SharedPtr<FormatOptions> JpegFormat::onGetFormatOptions(FileOp* fop) { SharedPtr<JpegOptions> jpeg_options(new JpegOptions()); try { // Configuration parameters jpeg_options->quality = get_config_float("JPEG", "Quality", 1.0f); // Interactive mode if (!App::instance()->isGui()) return jpeg_options; // Load the window to ask to the user the JPEG options he wants. FramePtr window(load_widget("jpeg_options.xml", "jpeg_options")); Slider* slider_quality; Widget* ok; get_widgets(window, "quality", &slider_quality, "ok", &ok, NULL); slider_quality->setValue(jpeg_options->quality * 10.0f); window->open_window_fg(); if (window->get_killer() == ok) { jpeg_options->quality = slider_quality->getValue() / 10.0f; set_config_float("JPEG", "Quality", jpeg_options->quality); } else { jpeg_options.reset(NULL); } return jpeg_options; } catch (base::Exception& e) { Console::showException(e); return SharedPtr<JpegOptions>(0); } }
/** * Shows the "New Sprite" dialog. */ void NewFileCommand::onExecute(Context* context) { JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box; int imgtype, w, h, bg, ncolors; char buf[1024]; Color bg_table[] = { Color::fromMask(), Color::fromRgb(0, 0, 0), Color::fromRgb(255, 255, 255), Color::fromRgb(255, 0, 255), app_get_colorbar()->getBgColor() }; // Load the window widget FramePtr window(load_widget("new_sprite.xml", "new_sprite")); get_widgets(window, "width", &width, "height", &height, "radio1", &radio1, "radio2", &radio2, "radio3", &radio3, "colors", &colors, "ok_button", &ok, "bg_box", &bg_box, NULL); // Default values: Indexed, 320x240, Background color imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED); imgtype = MID(IMAGE_RGB, imgtype, IMAGE_INDEXED); w = get_config_int("NewSprite", "Width", 320); h = get_config_int("NewSprite", "Height", 240); bg = get_config_int("NewSprite", "Background", 4); // Default = Background color ncolors = get_config_int("NewSprite", "Colors", 256); width->setTextf("%d", MAX(1, w)); height->setTextf("%d", MAX(1, h)); colors->setTextf("%d", MID(2, ncolors, 256)); // Select image-type switch (imgtype) { case IMAGE_RGB: radio1->setSelected(true); break; case IMAGE_GRAYSCALE: radio2->setSelected(true); break; case IMAGE_INDEXED: radio3->setSelected(true); break; } // Select background color jlistbox_select_index(bg_box, bg); // Open the window window->open_window_fg(); if (window->get_killer() == ok) { bool ok = false; // Get the options if (radio1->isSelected()) imgtype = IMAGE_RGB; else if (radio2->isSelected()) imgtype = IMAGE_GRAYSCALE; else if (radio3->isSelected()) imgtype = IMAGE_INDEXED; w = width->getTextInt(); h = height->getTextInt(); ncolors = colors->getTextInt(); bg = jlistbox_get_selected_index(bg_box); w = MID(1, w, 9999); h = MID(1, h, 9999); ncolors = MID(2, ncolors, 256); // Select the color Color color = Color::fromMask(); if (bg >= 0 && bg <= 4) { color = bg_table[bg]; ok = true; } if (ok) { // Save the configuration set_config_int("NewSprite", "Type", imgtype); set_config_int("NewSprite", "Width", w); set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Background", bg); // Create the new sprite ASSERT(imgtype == IMAGE_RGB || imgtype == IMAGE_GRAYSCALE || imgtype == IMAGE_INDEXED); ASSERT(w >= 1 && w <= 9999); ASSERT(h >= 1 && h <= 9999); UniquePtr<Document> document( Document::createBasicDocument(imgtype, w, h, (imgtype == IMAGE_INDEXED ? ncolors: 256))); Sprite* sprite(document->getSprite()); get_default_palette()->copyColorsTo(sprite->getCurrentPalette()); usprintf(buf, "Sprite-%04d", ++_sprite_counter); document->setFilename(buf); // If the background color isn't transparent, we have to // convert the `Layer 1' in a `Background' if (color.getType() != Color::MaskType) { Sprite* sprite = document->getSprite(); ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); static_cast<LayerImage*>(sprite->getCurrentLayer())->configureAsBackground(); image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, imgtype)); } // Show the sprite to the user context->addDocument(document); // Release the document as it is already owned by the context. // And put the document in a reliable editor. set_document_in_more_reliable_editor(document.release()); } } }
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; }