/* TranslationEditorDialog::onRBColourSelected * Called when the 'colour gradient' translation type radio button is * selected *******************************************************************/ void TranslationEditorDialog::onRBColourSelected(wxCommandEvent& e) { // Swap to target colour panel showGradientTarget(); // If a range is selected int index = list_translations->GetSelection(); if (index >= 0) { // Remove it translation.removeRange(index); // Recreate it translation.addRange(TRANS_COLOUR, index); TransRangeColour* tr = (TransRangeColour*)translation.getRange(index); // Origin range tr->setOStart(pal_canvas_original->getSelectionStart()); tr->setOEnd(pal_canvas_original->getSelectionEnd()); // Target colour gradient wxColour sc = cp_range_begin->GetColour(); wxColour ec = cp_range_end->GetColour(); tr->setDStart(rgba_t(sc.Red(), sc.Green(), sc.Blue())); tr->setDEnd(rgba_t(ec.Red(), ec.Green(), ec.Blue())); // Update UI updateListItem(index); openRange(index); updatePreviews(); } }
/* GLTexture::bgTex * Returns the global chequered 'background' texture *******************************************************************/ GLTexture& GLTexture::bgTex() { if (!tex_background.isLoaded()) { wxColour col1(bgtx_colour1); wxColour col2(bgtx_colour2); tex_background.genChequeredTexture(8, rgba_t(col1.Red(), col1.Green(), col1.Blue(), 255), rgba_t(col2.Red(), col2.Green(), col2.Blue(), 255)); } return tex_background; }
void UndoListView::updateItemAttr(long item) const { if (!manager) return; item_attr->SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT)); int index = manager->nUndoLevels() - item - 1; if (index == manager->getCurrentIndex()) item_attr->SetTextColour(WXCOL(rgba_t(0, 170, 0))); else if (index > manager->getCurrentIndex()) item_attr->SetTextColour(WXCOL(rgba_t(150, 150, 150))); }
void PolygonSplitter::testRender() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Draw vertices rgba_t(255, 255, 255, 255, 0).set_gl(); glBegin(GL_POINTS); for (unsigned a = 0; a < vertices.size(); a++) glVertex2d(vertices[a].x, vertices[a].y); glEnd(); // Draw original edges glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINES); for (int a = 0; a < split_edges_start; a++) { glVertex2d(vertices[edges[a].v1].x, vertices[edges[a].v1].y); glVertex2d(vertices[edges[a].v2].x, vertices[edges[a].v2].y); } glEnd(); // Draw split edges glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_LINES); for (unsigned a = split_edges_start; a < edges.size(); a++) { glVertex2d(vertices[edges[a].v1].x, vertices[edges[a].v1].y); glVertex2d(vertices[edges[a].v2].x, vertices[edges[a].v2].y); } glEnd(); }
/* ThingType::ThingType * ThingType class constructor *******************************************************************/ ThingType::ThingType(string name) { // Init variables this->name = name; this->angled = true; this->hanging = false; this->shrink = false; this->colour = rgba_t(170, 170, 180, 255, 0); this->radius = 20; this->height = -1; this->scaleX = 1.0; this->scaleY = 1.0; this->fullbright = false; this->decoration = false; this->decorate = false; this->solid = false; this->zeth = -1; this->nexttype = 0; this->nextargs = 0; this->flags = 0; this->tagged = 0; // Init args args[0].name = "Arg1"; args[1].name = "Arg2"; args[2].name = "Arg3"; args[3].name = "Arg4"; args[4].name = "Arg5"; }
/* QuickTextureOverlay3d::drawTexture * Draws the texture in the list at [index] *******************************************************************/ void QuickTextureOverlay3d::drawTexture(unsigned index, double x, double bottom, double size, float fade) { // Get texture if needed if (!textures[index].texture) { if (sel_type == 1) textures[index].texture = MapEditor::textureManager().getTexture(textures[index].name, false); else if (sel_type == 0) textures[index].texture = MapEditor::textureManager().getFlat(textures[index].name, false); else textures[index].texture = MapEditor::textureManager().getTexture(textures[index].name, true); } // Draw name double brightness = 0.5 + (size - 1.0); Drawing::drawText(textures[index].name, x, bottom + 2, rgba_t(brightness*255, brightness*255, brightness*255, brightness*255*fade), index == current_index ? Drawing::FONT_BOLD : Drawing::FONT_NORMAL, Drawing::ALIGN_CENTER); // Draw texture frect_t rect = Drawing::fitTextureWithin(textures[index].texture, x - 48*size, bottom - (96*size), x + 48*size, bottom, 0, 2); glColor4f(brightness, brightness, brightness, brightness*fade); textures[index].texture->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2d(rect.x1(), rect.y1()); glTexCoord2f(0.0f, 1.0f); glVertex2d(rect.x1(), rect.y2()); glTexCoord2f(1.0f, 1.0f); glVertex2d(rect.x2(), rect.y2()); glTexCoord2f(1.0f, 0.0f); glVertex2d(rect.x2(), rect.y1()); glEnd(); }
bool readImage(SImage& image, MemChunk& data, int index) { // Get image info SImage::info_t info; FIBITMAP* bm = getFIInfo(data, info); // Check it created/read ok if (!bm) { Global::error = "Unable to read image data (unsupported format?)"; return false; } // Get image palette if it exists RGBQUAD* bm_pal = FreeImage_GetPalette(bm); Palette palette; if (bm_pal) { int a = 0; int b = FreeImage_GetColorsUsed(bm); if (b > 256) b = 256; for (; a < b; a++) palette.setColour(a, rgba_t(bm_pal[a].rgbRed, bm_pal[a].rgbGreen, bm_pal[a].rgbBlue, 255)); } // Create image if (info.has_palette) image.create(info, &palette); else image.create(info); uint8_t* img_data = imageData(image); // Convert to 32bpp & flip vertically FIBITMAP* rgba = FreeImage_ConvertTo32Bits(bm); if (!rgba) { LOG_MESSAGE(1, "FreeImage_ConvertTo32Bits failed for image data"); Global::error = "Error reading PNG data"; return false; } FreeImage_FlipVertical(rgba); // Load raw RGBA data uint8_t* bits_rgba = FreeImage_GetBits(rgba); int c = 0; for (int a = 0; a < info.width * info.height; a++) { img_data[c++] = bits_rgba[a * 4 + 2]; // Red img_data[c++] = bits_rgba[a * 4 + 1]; // Green img_data[c++] = bits_rgba[a * 4]; // Blue img_data[c++] = bits_rgba[a * 4 + 3]; // Alpha } // Free memory FreeImage_Unload(rgba); FreeImage_Unload(bm); return true; }
void GfxColouriseDialog::setColour(string col) { wxColour colour(col); cp_colour->SetColour(colour); gfx_preview->getImage()->colourise(rgba_t(colour.Red(), colour.Green(), colour.Blue()), palette); gfx_preview->updateImageTexture(); gfx_preview->Refresh(); }
// Events void GfxColouriseDialog::onColourChanged(wxColourPickerEvent& e) { Misc::loadImageFromEntry(gfx_preview->getImage(), entry); wxColour col = cp_colour->GetColour(); gfx_preview->getImage()->colourise(rgba_t(col.Red(), col.Green(), col.Blue()), palette); gfx_preview->updateImageTexture(); gfx_preview->Refresh(); }
/******************************************************************* * GFXCOLOURISEDIALOG FUNCTIONS *******************************************************************/ GfxColouriseDialog::GfxColouriseDialog(wxWindow* parent, ArchiveEntry* entry, Palette8bit* pal) : wxDialog(parent, -1, "Colourise", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) { // Init variables this->entry = entry; this->palette = pal; // Set dialog icon wxIcon icon; icon.CopyFromBitmap(getIcon("t_colourise")); SetIcon(icon); // Setup main sizer wxBoxSizer* msizer = new wxBoxSizer(wxVERTICAL); SetSizer(msizer); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); msizer->Add(sizer, 1, wxEXPAND|wxALL, 6); // Add colour chooser wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); sizer->Add(hbox, 0, wxEXPAND|wxALL, 4); cp_colour = new wxColourPickerCtrl(this, -1, wxColour(255, 0, 0)); hbox->Add(new wxStaticText(this, -1, "Colour:"), 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4); hbox->Add(cp_colour, 0, wxEXPAND); // Add preview gfx_preview = new GfxCanvas(this, -1); sizer->Add(gfx_preview, 1, wxEXPAND|wxALL, 4); // Add buttons sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 0, wxEXPAND|wxBOTTOM, 4); // Setup preview gfx_preview->setViewType(GFXVIEW_CENTERED); gfx_preview->setPalette(pal); gfx_preview->SetInitialSize(wxSize(192, 192)); Misc::loadImageFromEntry(gfx_preview->getImage(), entry); wxColour col = cp_colour->GetColour(); gfx_preview->getImage()->colourise(rgba_t(col.Red(), col.Green(), col.Blue()), pal); gfx_preview->updateImageTexture(); // Init layout Layout(); // Bind events cp_colour->Bind(wxEVT_COLOURPICKER_CHANGED, &GfxColouriseDialog::onColourChanged, this); Bind(wxEVT_SIZE, &GfxColouriseDialog::onResize, this); // Setup dialog size SetInitialSize(wxSize(-1, -1)); SetMinSize(GetSize()); CenterOnParent(); }
/* TextStylePrefsPanel::updateBackground * Updates the background colour property of the currently selected * style *******************************************************************/ void TextStylePrefsPanel::updateBackground() { if (cb_override_background->GetValue()) { wxColour wxc = cp_background->GetColour(); ts_current->setBackground(rgba_t(wxc.Red(), wxc.Green(), wxc.Blue(), 255)); } else { ts_current->clearBackground(); } }
/* GLTexture::averageColour * Returns the average colour of the texture *******************************************************************/ rgba_t GLTexture::averageColour(rect_t area) { // Check texture is loaded if (!loaded || tex.empty()) return COL_BLACK; // Empty area rect means full texture if (area.tl.x == area.br.x && area.tl.y == area.br.y) area.set(0, 0, width, height); // Clamp area to texture if (area.tl.x < 0) area.tl.x = 0; if (area.tl.y < 0) area.tl.y = 0; if ((unsigned)area.br.x > width) area.br.x = width; if ((unsigned)area.br.y > height) area.br.y = height; // Get texture pixels uint8_t* pixels = new uint8_t[width*height*8]; glBindTexture(GL_TEXTURE_2D, tex[0].id); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Add colour values unsigned red = 0; unsigned green = 0; unsigned blue = 0; unsigned npix = 0; // Go through area for (int y = area.tl.y; y < area.br.y; y++) { for (int x = area.tl.x; x < area.br.x; x++) { // Add pixel unsigned c = (y * width * 4) + (x * 4); red += pixels[c++]; green += pixels[c++]; blue += pixels[c++]; npix++; } } // Clean up delete[] pixels; // Return average colour return rgba_t(red/npix, green/npix, blue/npix, 255); }
wxColour Drawing::darkColour(const wxColour& colour, float percent) { if(percent == 0) { return colour; } // Convert to HSL hsl_t hsl = Misc::rgbToHsl(rgba_t(colour.Red(), colour.Green(), colour.Blue())); // Decrease luminance hsl.l -= (float)((percent * 5.0)/100.0); if (hsl.l < 0) hsl.l = 0; rgba_t rgb = Misc::hslToRgb(hsl); return wxColour(rgb.r, rgb.g, rgb.b); }
/* SImage::getPixel * Returns the colour of the pixel at [x,y] in the image, or black+ * invisible if out of range *******************************************************************/ rgba_t SImage::getPixel(unsigned x, unsigned y, Palette8bit* pal) { // Get pixel index unsigned index = y * getStride() + x * getBpp(); // Check it if (index >= unsigned(width*height*getBpp())) return rgba_t(0, 0, 0, 0); // Get colour at pixel rgba_t col; if (type == RGBA) { col.r = data[index]; col.g = data[index+1]; col.b = data[index+2]; col.a = data[index+3]; } else if (type == PALMASK) { // Get palette to use if (has_palette || !pal) pal = &palette; col.set(pal->colour(data[index])); } else if (type == ALPHAMAP) { col.r = data[index]; col.g = data[index]; col.b = data[index]; col.a = data[index]; } return col; }
rgba_t GfxTintDialog::getColour() { wxColour col = cp_colour->GetColour(); return rgba_t(col.Red(), col.Green(), col.Blue()); }
/* EntryType::readEntryTypeDefinition * Reads in a block of entry type definitions. Returns false if there * was a parsing error, true otherwise *******************************************************************/ bool EntryType::readEntryTypeDefinition(MemChunk& mc) { // Parse the definition Parser p; p.parseText(mc); // Get entry_types tree ParseTreeNode* pt_etypes = (ParseTreeNode*)(p.parseTreeRoot()->getChild("entry_types")); // Check it exists if (!pt_etypes) return false; // Go through all parsed types for (unsigned a = 0; a < pt_etypes->nChildren(); a++) { // Get child as ParseTreeNode ParseTreeNode* typenode = (ParseTreeNode*)pt_etypes->getChild(a); // Create new entry type EntryType* ntype = new EntryType(typenode->getName().Lower()); // Copy from existing type if inherited if (!typenode->getInherit().IsEmpty()) { EntryType* parent_type = EntryType::getType(typenode->getInherit().Lower()); if (parent_type != EntryType::unknownType()) parent_type->copyToType(ntype); else wxLogMessage("Warning: Entry type %s inherits from unknown type %s", CHR(ntype->getId()), CHR(typenode->getInherit())); } // Go through all parsed fields for (unsigned b = 0; b < typenode->nChildren(); b++) { // Get child as ParseTreeNode ParseTreeNode* fieldnode = (ParseTreeNode*)typenode->getChild(b); // Process it if (S_CMPNOCASE(fieldnode->getName(), "name")) // Name field { ntype->name = fieldnode->getStringValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "detectable")) // Detectable field { ntype->detectable = fieldnode->getBoolValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "export_ext")) // Export Extension field { ntype->extension = fieldnode->getStringValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "format")) // Format field { string format_string = fieldnode->getStringValue(); ntype->format = EntryDataFormat::getFormat(format_string); // Warn if undefined format if (ntype->format == EntryDataFormat::anyFormat()) wxLogMessage("Warning: Entry type %s requires undefined format %s", CHR(ntype->getId()), CHR(format_string)); } else if (S_CMPNOCASE(fieldnode->getName(), "icon")) // Icon field { ntype->icon = fieldnode->getStringValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "editor")) // Editor field (to be removed) { ntype->editor = fieldnode->getStringValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "section")) // Section field { ntype->section = fieldnode->getStringValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "match_ext")) // Match Extension field { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->match_extension.push_back(fieldnode->getStringValue(v).Lower()); } else if (S_CMPNOCASE(fieldnode->getName(), "match_name")) // Match Name field { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->match_name.push_back(fieldnode->getStringValue(v).Lower()); } else if (S_CMPNOCASE(fieldnode->getName(), "match_extorname")) // Match name or extension { ntype->matchextorname = fieldnode->getBoolValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "size")) // Size field { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->match_size.push_back(fieldnode->getIntValue(v)); } else if (S_CMPNOCASE(fieldnode->getName(), "min_size")) // Min Size field { ntype->size_limit[0] = fieldnode->getIntValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "max_size")) // Max Size field { ntype->size_limit[1] = fieldnode->getIntValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "size_multiple")) // Size Multiple field { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->size_multiple.push_back(fieldnode->getIntValue(v)); } else if (S_CMPNOCASE(fieldnode->getName(), "reliability")) // Reliability field { ntype->reliability = fieldnode->getIntValue(); } else if (S_CMPNOCASE(fieldnode->getName(), "match_archive")) // Archive field { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->match_archive.push_back(fieldnode->getStringValue(v).Lower()); } else if (S_CMPNOCASE(fieldnode->getName(), "extra")) // Extra properties { for (unsigned v = 0; v < fieldnode->nValues(); v++) ntype->extra.addFlag(fieldnode->getStringValue(v)); } else if (S_CMPNOCASE(fieldnode->getName(), "category")) // Type category { ntype->category = fieldnode->getStringValue(); // Add to category list if needed bool exists = false; for (unsigned b = 0; b < entry_categories.size(); b++) { if (S_CMPNOCASE(entry_categories[b], ntype->category)) { exists = true; break; } } if (!exists) entry_categories.push_back(ntype->category); } else if (S_CMPNOCASE(fieldnode->getName(), "image_format")) // Image format hint ntype->extra["image_format"] = fieldnode->getStringValue(0); else if (S_CMPNOCASE(fieldnode->getName(), "colour")) // Colour { if (fieldnode->nValues() >= 3) ntype->colour = rgba_t(fieldnode->getIntValue(0), fieldnode->getIntValue(1), fieldnode->getIntValue(2)); else wxLogMessage("Not enough colour components defined for entry type %s", CHR(ntype->getId())); } else { // Unhandled properties can go into 'extra', only their first value is kept ntype->extra[fieldnode->getName()] = fieldnode->getStringValue(); } } //ntype->dump(); ntype->addToList(); } return true; }
/* EntryType::loadEntryTypes * Loads all built-in and custom user entry types *******************************************************************/ bool EntryType::loadEntryTypes() { EntryDataFormat* fmt_any = EntryDataFormat::anyFormat(); // Setup unknown type etype_unknown.format = fmt_any; etype_unknown.icon = "e_unknown"; etype_unknown.detectable = false; etype_unknown.reliability = 0; etype_unknown.addToList(); // Setup folder type etype_folder.format = fmt_any; etype_folder.icon = "e_folder"; etype_folder.name = "Folder"; etype_folder.detectable = false; etype_folder.addToList(); // Setup marker type etype_marker.format = fmt_any; etype_marker.icon = "e_marker"; etype_marker.name = "Marker"; etype_marker.detectable = false; etype_marker.category = ""; // No category, markers only appear when 'All' categories shown etype_marker.addToList(); // Setup map marker type etype_map.format = fmt_any; etype_map.icon = "e_map"; etype_map.name = "Map Marker"; etype_map.category = "Maps"; // Should appear with maps etype_map.detectable = false; etype_map.colour = rgba_t(0, 255, 0); etype_map.addToList(); // -------- READ BUILT-IN TYPES --------- // Get builtin entry types from resource archive Archive* res_archive = theArchiveManager->programResourceArchive(); // Check resource archive exists if (!res_archive) { wxLogMessage("Error: No resource archive open!"); return false; } // Get entry types directory ArchiveTreeNode* et_dir = res_archive->getDir("config/entry_types/"); // Check it exists if (!et_dir) { wxLogMessage("Error: config/entry_types does not exist in slade.pk3"); return false; } // Read in each file in the directory bool etypes_read = false; for (unsigned a = 0; a < et_dir->numEntries(); a++) { if (readEntryTypeDefinition(et_dir->getEntry(a)->getMCData())) etypes_read = true; } // Warn if no types were read (this shouldn't happen unless the resource archive is corrupted) if (!etypes_read) wxLogMessage("Warning: No built-in entry types could be loaded from slade.pk3"); // -------- READ CUSTOM TYPES --------- // If the directory doesn't exist create it if (!wxDirExists(appPath("entry_types", DIR_USER))) wxMkdir(appPath("entry_types", DIR_USER)); // Open the custom palettes directory wxDir res_dir; res_dir.Open(appPath("entry_types", DIR_USER)); // Go through each file in the directory string filename = wxEmptyString; bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES); while (files) { // Load file data MemChunk mc; mc.importFile(res_dir.GetName() + "/" + filename); // Parse file readEntryTypeDefinition(mc); // Next file files = res_dir.GetNext(&filename); } return true; }
constexpr rgba_t operator*(float value) const { return rgba_t(r * value, g * value, b * value, a * value); }
GtkWidget* setup_sector_edit() { sector_t* sector; if (selected_items.size() == 0) sector = map.sectors[hilight_item]; else sector = map.sectors[selected_items[0]]; // Init data sedit_data.f_height = sector->f_height; sedit_data.c_height = sector->c_height; sedit_data.f_tex = sector->f_tex; sedit_data.c_tex = sector->c_tex; sedit_data.light = sector->light; sedit_data.special = sector->special; sedit_data.tag = sector->tag; sedit_data.f_height_consistent = true; sedit_data.c_height_consistent = true; sedit_data.f_tex_consistent = true; sedit_data.c_tex_consistent = true; sedit_data.light_consistent = true; sedit_data.special_consistent = true; sedit_data.tag_consistent = true; // Check for inconsistency if (selected_items.size() > 1) { for (int a = 0; a < selected_items.size(); a++) { if (map.sectors[selected_items[a]]->f_height != sedit_data.f_height) sedit_data.f_height_consistent = false; if (map.sectors[selected_items[a]]->c_height != sedit_data.c_height) sedit_data.c_height_consistent = false; if (map.sectors[selected_items[a]]->f_tex != sedit_data.f_tex) sedit_data.f_tex_consistent = false; if (map.sectors[selected_items[a]]->c_tex != sedit_data.c_tex) sedit_data.c_tex_consistent = false; if (map.sectors[selected_items[a]]->light != sedit_data.light) sedit_data.light_consistent = false; if (map.sectors[selected_items[a]]->special != sedit_data.special) sedit_data.special_consistent = false; if (map.sectors[selected_items[a]]->tag != sedit_data.tag) sedit_data.tag_consistent = false; } } if (sedit_tbox_floor) { delete sedit_tbox_floor; sedit_tbox_floor = NULL; } if (sedit_tbox_ceil) { delete sedit_tbox_ceil; sedit_tbox_ceil = NULL; } GtkWidget* main_vbox = gtk_vbox_new(false, 0); GtkWidget* hbox = gtk_hbox_new(true, 0); gtk_box_pack_start(GTK_BOX(main_vbox), hbox, true, true, 0); // FLOOR FRAME GtkWidget *frame = gtk_frame_new("Floor"); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(hbox), frame, true, true, 0); GtkWidget *vbox = gtk_vbox_new(false, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_container_add(GTK_CONTAINER(frame), vbox); GtkWidget *entry = gtk_entry_new(); // Texture box sedit_tbox_floor = new tex_box_t(sedit_data.f_tex, 2, 2.0f, rgba_t(180, 180, 180, 255, 0)); sedit_tbox_floor->set_size(128, 128); frame = gtk_aspect_frame_new(NULL, 0.5, 0.5, 1.0, true); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(frame), sedit_tbox_floor->widget); gtk_widget_set_events(sedit_tbox_floor->widget, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(sedit_tbox_floor->widget), "button_press_event", G_CALLBACK(sedit_ftex_clicked), entry); gtk_box_pack_start(GTK_BOX(vbox), frame, true, true, 0); // Entry gtk_entry_set_alignment(GTK_ENTRY(entry), 0.5); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_ftex_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(vbox), entry, false, false , 4); if (sedit_data.f_tex_consistent) gtk_entry_set_text(GTK_ENTRY(entry), sedit_data.f_tex.c_str()); // Height GtkWidget *hbox2 = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox2, false, false, 4); GtkWidget *label = gtk_label_new("Height: "); gtk_box_pack_start(GTK_BOX(hbox2), label, false, false, 0); entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_fheight_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(hbox2), entry, true, true, 0); if (sedit_data.f_height_consistent) gtk_entry_set_text(GTK_ENTRY(entry), parse_string("%d", sedit_data.f_height).c_str()); // CEILING FRAME frame = gtk_frame_new("Ceiling"); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(hbox), frame, true, true, 0); vbox = gtk_vbox_new(false, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_container_add(GTK_CONTAINER(frame), vbox); entry = gtk_entry_new(); // Texture box sedit_tbox_ceil = new tex_box_t(sedit_data.c_tex, 2, 2.0f, rgba_t(180, 180, 180, 255, 0)); sedit_tbox_ceil->set_size(128, 128); frame = gtk_aspect_frame_new(NULL, 0.5, 0.5, 1.0, true); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); gtk_widget_set_events(sedit_tbox_ceil->widget, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(sedit_tbox_ceil->widget), "button_press_event", G_CALLBACK(sedit_ctex_clicked), entry); gtk_container_add(GTK_CONTAINER(frame), sedit_tbox_ceil->widget); gtk_box_pack_start(GTK_BOX(vbox), frame, true, true, 0); // Entry gtk_entry_set_alignment(GTK_ENTRY(entry), 0.5); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_ctex_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(vbox), entry, false, false , 4); if (sedit_data.c_tex_consistent) gtk_entry_set_text(GTK_ENTRY(entry), sedit_data.c_tex.c_str()); // Height hbox2 = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox2, false, false, 4); label = gtk_label_new("Height: "); gtk_box_pack_start(GTK_BOX(hbox2), label, false, false, 0); entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_cheight_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(hbox2), entry, true, true, 0); if (sedit_data.c_height_consistent) gtk_entry_set_text(GTK_ENTRY(entry), parse_string("%d", sedit_data.c_height).c_str()); // PROPERTIES FRAME frame = gtk_frame_new("Properties"); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(main_vbox), frame, false, false, 0); vbox = gtk_vbox_new(false, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_container_add(GTK_CONTAINER(frame), vbox); // Special hbox = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, false, false, 0); label = gtk_label_new("Special: "); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), label, true, true, 0); entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_special_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(hbox), entry, false, false, 4); if (sedit_data.special_consistent) gtk_entry_set_text(GTK_ENTRY(entry), parse_string("%d", sedit_data.special).c_str()); GtkWidget *button = gtk_button_new_with_label("Change"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(sedit_change_special_clicked), entry); gtk_widget_set_size_request(button, 96, -1); gtk_box_pack_start(GTK_BOX(hbox), button, false, false, 0); // Tag hbox = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, false, false, 4); label = gtk_label_new("Tag: "); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), label, true, true, 0); entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 32, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_tag_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(hbox), entry, false, false, 4); if (sedit_data.tag_consistent) gtk_entry_set_text(GTK_ENTRY(entry), parse_string("%d", sedit_data.tag).c_str()); button = gtk_button_new_with_label("Find Unused"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(sedit_find_tag_clicked), entry); gtk_widget_set_size_request(button, 96, -1); gtk_box_pack_start(GTK_BOX(hbox), button, false, false, 0); // Light hbox = gtk_hbox_new(false, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, false, false, 0); label = gtk_label_new("Light Level: "); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), label, true, true, 0); entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 48, -1); g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(sedit_light_entry_changed), NULL); gtk_box_pack_start(GTK_BOX(hbox), entry, false, false, 0); if (sedit_data.light_consistent) gtk_entry_set_text(GTK_ENTRY(entry), parse_string("%d", sedit_data.light).c_str()); return main_vbox; }
void LineTextureOverlay::drawTexture(float alpha, int size, tex_inf_t& tex, string position) { // Get colours rgba_t col_bg = ColourConfiguration::getColour("map_overlay_background"); rgba_t col_fg = ColourConfiguration::getColour("map_overlay_foreground"); rgba_t col_sel = ColourConfiguration::getColour("map_hilight"); col_fg.a = col_fg.a*alpha; // Draw background int halfsize = size*0.5; glEnable(GL_TEXTURE_2D); rgba_t(255, 255, 255, 255*alpha, 0).set_gl(); glPushMatrix(); glTranslated(tex.position.x - halfsize, tex.position.y - halfsize, 0); GLTexture::bgTex().draw2dTiled(size, size); glPopMatrix(); GLTexture* tex_first = NULL; if (tex.textures.size() > 0) { // Draw first texture rgba_t(255, 255, 255, 255*alpha, 0).set_gl(); tex_first = theMapEditor->textureManager().getTexture(tex.textures[0], theGameConfiguration->mixTexFlats()); Drawing::drawTextureWithin(tex_first, tex.position.x - halfsize, tex.position.y - halfsize, tex.position.x + halfsize, tex.position.y + halfsize, 0, 2); // Draw up to 4 subsequent textures (overlaid) rgba_t(255, 255, 255, 127*alpha, 0).set_gl(); for (unsigned a = 1; a < tex.textures.size() && a < 5; a++) { Drawing::drawTextureWithin(theMapEditor->textureManager().getTexture(tex.textures[a], theGameConfiguration->mixTexFlats()), tex.position.x - halfsize, tex.position.y - halfsize, tex.position.x + halfsize, tex.position.y + halfsize, 0, 2); } } else return; glDisable(GL_TEXTURE_2D); // Draw outline if (tex.hover) { rgba_t(col_sel.r, col_sel.g, col_sel.b, 255*alpha, 0).set_gl(); glLineWidth(3.0f); } else { rgba_t(col_fg.r, col_fg.g, col_fg.b, 255*alpha, 0).set_gl(); glLineWidth(1.5f); } Drawing::drawRect(tex.position.x-halfsize, tex.position.y-halfsize, tex.position.x+halfsize, tex.position.y+halfsize); // Draw position text Drawing::drawText(position + ":", tex.position.x, tex.position.y - halfsize - 18, col_fg, Drawing::FONT_BOLD, Drawing::ALIGN_CENTER); // Determine texture name text string str_texture; if (tex.textures.size() == 1) str_texture = S_FMT("%s (%dx%d)", CHR(tex.textures[0]), tex_first->getWidth(), tex_first->getHeight()); else if (tex.textures.size() > 1) str_texture = S_FMT("Multiple (%d)", tex.textures.size()); else str_texture = "- (None)"; // Draw texture name Drawing::drawText(str_texture, tex.position.x, tex.position.y + halfsize + 2, col_fg, Drawing::FONT_BOLD, Drawing::ALIGN_CENTER); }
/* TranslationEditorDialog::onEndColourChanged * Called when the target gradient end colour is changed *******************************************************************/ void TranslationEditorDialog::onEndColourChanged(wxColourPickerEvent& e) { // Set end colour to selected colour wxColour col = cp_range_end->GetColour(); setEndColour(rgba_t(col.Red(), col.Green(), col.Blue())); }
/* SImage::applyTranslation * Applies a palette translation to the image *******************************************************************/ bool SImage::applyTranslation(Translation* tr, Palette8bit* pal) { // Check image is ok if (!data) return false; // Can't apply a translation to a non-paletted image if (type != PALMASK) return false; // Get palette to use if (has_palette || !pal) pal = &palette; // Go through pixels for (int p = 0; p < width*height; p++) { uint8_t i = data[p]; // No need to process transparent pixels if (mask && mask[p] == 0) continue; // Go through each translation component for (unsigned a = 0; a < tr->nRanges(); a++) { TransRange* r = tr->getRange(a); // Palette range translation if (r->getType() == TRANS_PALETTE) { TransRangePalette* tp = (TransRangePalette*)r; // Check pixel is within translation range if (i >= tp->oStart() && i <= tp->oEnd()) { // Figure out how far along the range this colour is double range_frac = 0; if (tp->oStart() != tp->oEnd()) range_frac = double(i - tp->oStart()) / double(tp->oEnd() - tp->oStart()); // Determine destination palette index uint8_t di = tp->dStart() + range_frac * (tp->dEnd() - tp->dStart()); // Apply new colour data[p] = di; } } // Colour range else if (r->getType() == TRANS_COLOUR) { TransRangeColour* tc = (TransRangeColour*)r; // Check pixel is within translation range if (i >= tc->oStart() && i <= tc->oEnd()) { // Figure out how far along the range this colour is double range_frac = 0; if (tc->oStart() != tc->oEnd()) range_frac = double(i - tc->oStart()) / double(tc->oEnd() - tc->oStart()); // Determine destination colour uint8_t r = tc->dStart().r + range_frac * (tc->dEnd().r - tc->dStart().r); uint8_t g = tc->dStart().g + range_frac * (tc->dEnd().g - tc->dStart().g); uint8_t b = tc->dStart().b + range_frac * (tc->dEnd().b - tc->dStart().b); // Find nearest colour in palette uint8_t di = pal->nearestColour(rgba_t(r, g, b)); // Apply new colour data[p] = di; } } // Desaturated colour range else if (r->getType() == TRANS_DESAT) { TransRangeDesat* td = (TransRangeDesat*)r; // Check pixel is within translation range if (i >= td->oStart() && i <= td->oEnd()) { // Get greyscale colour rgba_t col = pal->colour(i); float grey = (col.r*0.3f + col.g*0.59f + col.b*0.11f) / 255.0f; // Determine destination colour uint8_t r = MIN(255, int((td->dSr() + grey*(td->dEr() - td->dSr()))*255.0f)); uint8_t g = MIN(255, int((td->dSg() + grey*(td->dEg() - td->dSg()))*255.0f)); uint8_t b = MIN(255, int((td->dSb() + grey*(td->dEb() - td->dSb()))*255.0f)); // Find nearest colour in palette uint8_t di = pal->nearestColour(rgba_t(r, g, b)); // Apply new colour data[p] = di; } } } } return true; }
/* TranslationEditorDialog::onBeginColourChanged * Called when the target gradient start colour is changed *******************************************************************/ void TranslationEditorDialog::onBeginColourChanged(wxColourPickerEvent& e) { // Set start colour to selected colour wxColour col = cp_range_begin->GetColour(); setStartColour(rgba_t(col.Red(), col.Green(), col.Blue())); }
GLTexture& GLTexture::missingTex() { if (!tex_missing.isLoaded()) tex_missing.genChequeredTexture(8, rgba_t(0, 0, 0), rgba_t(255, 0, 0)); return tex_missing; }
rgba_t getColour() { wxColour col = cp_colour->GetColour(); return rgba_t(col.Red(), col.Green(), col.Blue()); }
void SAuiDockArt::DrawCaption(wxDC& dc, wxWindow *window, const wxString& text, const wxRect& rect, wxAuiPaneInfo& pane) { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetFont(m_captionFont); dc.SetBrush(wxBrush(captionBackColour)); dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); //dc.SetPen(m_borderPen); //dc.SetBrush(wxBrush(Drawing::darkColour(captionBackColour, 2.0f))); //dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); wxColor sepCol; int l = rgba_t(captionBackColour.Red(), captionBackColour.Green(), captionBackColour.Blue()).greyscale().r; if (l < 100) sepCol = Drawing::lightColour(captionBackColour, 2.0f); else sepCol = Drawing::darkColour(captionBackColour, 2.0f); //dc.SetPen(wxPen(sepCol)); //dc.DrawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width, rect.y + rect.height - 1); dc.SetBrush(wxBrush(sepCol)); dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height + 1); int caption_offset = 0; if (pane.icon.IsOk()) { DrawIcon(dc, rect, pane); caption_offset += pane.icon.GetWidth() + 3; } dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); wxRect clip_rect = rect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if (pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if (pane.HasPinButton()) clip_rect.width -= m_buttonSize; if (pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(dc, text, clip_rect.width); wxCoord w, h; dc.GetTextExtent(draw_text, &w, &h); dc.SetClippingRegion(clip_rect); #ifdef __WXMSW__ dc.DrawText(draw_text, rect.x + 5 + caption_offset, rect.y + (rect.height / 2) - (h / 2)); #else dc.DrawText(draw_text, rect.x + 5 + caption_offset, rect.y + (rect.height / 2) - (h / 2) + 1); #endif //dc.SetPen(wxPen(captionAccentColour)); //dc.DrawLine(rect.x + w + 8, rect.y + (rect.height / 2) - 1, rect.x + rect.width - 16, rect.y + (rect.height / 2) - 1); //dc.DrawLine(rect.x + w + 8, rect.y + (rect.height / 2) + 1, rect.x + rect.width - 16, rect.y + (rect.height / 2) + 1); dc.DestroyClippingRegion(); }
gboolean browser_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer data) { int width = w->allocation.width / browser_columns; rows = (tex_names.size() / browser_columns) + 1; int top = gtk_range_get_value(GTK_RANGE(browse_vscroll)); // Set sizes for row and page steps (for the scrollbar) int rows_page = w->allocation.height / width; gtk_range_set_increments(GTK_RANGE(browse_vscroll), width, rows_page * width); GdkGLContext *context = gtk_widget_get_gl_context(w); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(w); if (!gdk_gl_drawable_gl_begin(gldrawable, context)) return false; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int sel_index = -1; int a = 0; for (int row = 0; row < rows; row++) { for (int col = 0; col < browser_columns; col++) { if (a >= tex_names.size()) continue; rect_t rect(col * width, (row * width) - top, width, width, 0); glLineWidth(2.0f); if (selected_tex == tex_names[a]) { draw_rect(rect, rgba_t(0, 180, 255, 150, 0), true); draw_rect(rect, rgba_t(100, 220, 255, 255, 0), false); sel_index = a; } glLineWidth(1.0f); rect.resize(-8, -8); if (((row + 1) * width) > top && (row * width) < (top + w->allocation.height)) { if (!browse_sprites) { if (tex_names[a] != "-") draw_texture_scale(rect, tex_names[a], 0); draw_text(rect.x1() + (width/2) - 8, rect.y2() - 4, rgba_t(255, 255, 255, 255, 0), 1, tex_names[a].c_str()); } else draw_texture_scale(rect, browsesprites[a], 3); } a++; } } if (browse_sprites && sel_index != -1) draw_text(0, 0, rgba_t(255, 255, 255, 255, 0), 0, tex_names[sel_index].c_str()); if (gdk_gl_drawable_is_double_buffered(gldrawable)) gdk_gl_drawable_swap_buffers(gldrawable); else glFlush(); gdk_gl_drawable_gl_end(gldrawable); return false; }
/* GfxConvDialog::setupLayout * Sets up the dialog UI layout *******************************************************************/ void GfxConvDialog::setupLayout() { wxBoxSizer* msizer = new wxBoxSizer(wxVERTICAL); SetSizer(msizer); wxBoxSizer* m_vbox = new wxBoxSizer(wxVERTICAL); msizer->Add(m_vbox, 1, wxEXPAND|wxALL, 6); // Add current format label label_current_format = new wxStaticText(this, -1, "Current Format:"); m_vbox->Add(label_current_format, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxTOP, 8); // Add 'Convert To' combo box wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); m_vbox->Add(hbox, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 4); hbox->Add(new wxStaticText(this, -1, "Convert to:"), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); combo_target_format = new wxChoice(this, -1); hbox->Add(combo_target_format, 1, wxEXPAND|wxALL, 4); // Add Gfx previews wxStaticBox* frame = new wxStaticBox(this, -1, "Graphic"); wxStaticBoxSizer* framesizer = new wxStaticBoxSizer(frame, wxHORIZONTAL); m_vbox->Add(framesizer, 1, wxEXPAND|wxALL, 4); wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL); framesizer->Add(vbox, 1, wxEXPAND|wxALL, 0); vbox->Add(new wxStaticText(this, -1, "Current Graphic"), 0, wxEXPAND|wxLEFT|wxRIGHT, 4); gfx_current = new GfxCanvas(this, -1); gfx_current->SetInitialSize(wxSize(192, 192)); gfx_current->setViewType(GFXVIEW_CENTERED); vbox->Add(gfx_current->toPanel(this), 1, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 4); pal_chooser_current = new PaletteChooser(this, -1); pal_chooser_current->selectPalette(current_palette_name); vbox->Add(pal_chooser_current, 0, wxEXPAND|wxALL, 4); vbox = new wxBoxSizer(wxVERTICAL); framesizer->Add(vbox, 1, wxEXPAND|wxALL, 0); vbox->Add(new wxStaticText(this, -1, "Converted Graphic"), 0, wxEXPAND|wxLEFT|wxRIGHT, 4); gfx_target = new GfxCanvas(this, -1); gfx_target->SetInitialSize(wxSize(192, 192)); gfx_target->setViewType(1); vbox->Add(gfx_target->toPanel(this), 1, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 4); hbox = new wxBoxSizer(wxHORIZONTAL); pal_chooser_target = new PaletteChooser(this, -1); pal_chooser_target->selectPalette(target_palette_name); hbox->Add(pal_chooser_target, 1, wxEXPAND|wxRIGHT, 4); btn_colorimetry_settings = new wxBitmapButton(this, -1, Icons::getIcon(Icons::GENERAL, "settings"), wxDefaultPosition, wxDefaultSize); btn_colorimetry_settings->SetToolTip("Adjust Colorimetry Settings..."); hbox->Add(btn_colorimetry_settings, 0, wxEXPAND, 0); vbox->Add(hbox, 0, wxEXPAND | wxALL, 4); // 'Enable transparency' checkbox cb_enable_transparency = new wxCheckBox(this, -1, "Enable Transparency"); cb_enable_transparency->SetValue(true); cb_enable_transparency->SetToolTip("Uncheck this to remove any existing transparency from the graphic"); m_vbox->AddSpacer(4); m_vbox->Add(cb_enable_transparency, 0, wxEXPAND|wxALL, 4); // Add transparency options frame = new wxStaticBox(this, -1, "Transparency Options"); framesizer = new wxStaticBoxSizer(frame, wxVERTICAL); m_vbox->Add(framesizer, 0, wxEXPAND|wxALL, 4); wxBoxSizer* vbox_ttypes = new wxBoxSizer(wxVERTICAL); framesizer->Add(vbox_ttypes, 1, wxEXPAND|wxALL, 0); // Keep existing transparency hbox = new wxBoxSizer(wxHORIZONTAL); vbox_ttypes->Add(hbox, 0, wxEXPAND|wxALL, 0); rb_transparency_existing = new wxRadioButton(this, 100, "Existing w/Threshold:", wxDefaultPosition, wxDefaultSize, wxRB_GROUP); rb_transparency_existing->SetValue(true); hbox->Add(rb_transparency_existing, 0, wxEXPAND|wxALL, 4); // Alpha threshold slider_alpha_threshold = new wxSlider(this, -1, 0, 0, 255, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS|wxSL_BOTTOM); slider_alpha_threshold->SetToolTip("Specifies the 'cutoff' transparency level, anything above this will be fully opaque, anything equal or below will be completely transparent"); hbox->Add(slider_alpha_threshold, 1, wxEXPAND|wxALL, 4); // Transparent colour hbox = new wxBoxSizer(wxHORIZONTAL); vbox_ttypes->Add(hbox, 0, wxEXPAND|wxALL, 0); rb_transparency_colour = new wxRadioButton(this, 101, "Transparent Colour:", wxDefaultPosition, wxDefaultSize, 0); rb_transparency_colour->SetValue(false); hbox->Add(rb_transparency_colour, 0, wxEXPAND|wxALL, 4); colbox_transparent = new ColourBox(this, -1, false); colbox_transparent->setColour(rgba_t(0, 255, 255, 255)); hbox->Add(colbox_transparent, 0, wxEXPAND|wxALL, 4); // From brightness rb_transparency_brightness = new wxRadioButton(this, 102, "Transparency from Brightness"); rb_transparency_brightness->SetValue(false); vbox_ttypes->Add(rb_transparency_brightness, 0, wxEXPAND|wxALL, 4); // Buttons hbox = new wxBoxSizer(wxHORIZONTAL); m_vbox->Add(hbox, 0, wxEXPAND|wxALL, 4); btn_convert = new wxButton(this, -1, "Convert"); btn_convert_all = new wxButton(this, -1, "Convert All"); btn_skip = new wxButton(this, -1, "Skip"); btn_skip_all = new wxButton(this, -1, "Skip All"); hbox->AddStretchSpacer(1); hbox->Add(btn_convert, 0, wxEXPAND|wxRIGHT, 4); hbox->Add(btn_convert_all, 0, wxEXPAND|wxRIGHT, 4); hbox->Add(btn_skip, 0, wxEXPAND|wxRIGHT, 4); hbox->Add(btn_skip_all, 0, wxEXPAND, 0); // Bind events Bind(wxEVT_SIZE, &GfxConvDialog::onResize, this); btn_convert->Bind(wxEVT_BUTTON, &GfxConvDialog::onBtnConvert, this); btn_convert_all->Bind(wxEVT_BUTTON, &GfxConvDialog::onBtnConvertAll, this); btn_skip->Bind(wxEVT_BUTTON, &GfxConvDialog::onBtnSkip, this); btn_skip_all->Bind(wxEVT_BUTTON, &GfxConvDialog::onBtnSkipAll, this); combo_target_format->Bind(wxEVT_CHOICE, &GfxConvDialog::onTargetFormatChanged, this); pal_chooser_current->Bind(wxEVT_CHOICE, &GfxConvDialog::onCurrentPaletteChanged, this); pal_chooser_target->Bind(wxEVT_CHOICE, &GfxConvDialog::onTargetPaletteChanged, this); slider_alpha_threshold->Bind(wxEVT_SLIDER, &GfxConvDialog::onAlphaThresholdChanged, this); cb_enable_transparency->Bind(wxEVT_CHECKBOX, &GfxConvDialog::onEnableTransparencyChanged, this); rb_transparency_colour->Bind(wxEVT_RADIOBUTTON, &GfxConvDialog::onTransTypeChanged, this); rb_transparency_existing->Bind(wxEVT_RADIOBUTTON, &GfxConvDialog::onTransTypeChanged, this); rb_transparency_brightness->Bind(wxEVT_RADIOBUTTON, &GfxConvDialog::onTransTypeChanged, this); Bind(wxEVT_COLOURBOX_CHANGED, &GfxConvDialog::onTransColourChanged, this, colbox_transparent->GetId()); gfx_current->Bind(wxEVT_LEFT_DOWN, &GfxConvDialog::onPreviewCurrentMouseDown, this); btn_colorimetry_settings->Bind(wxEVT_BUTTON, &GfxConvDialog::onBtnColorimetrySettings, this); // Autosize to fit contents (and set this as the minimum size) //SetInitialSize(wxSize(-1, -1)); SetMinClientSize(msizer->GetMinSize()); }
/* GfxCanvas::drawImage * Draws the image (reloads the image as a texture each time, will * change this later...) *******************************************************************/ void GfxCanvas::drawImage() { // Check image is valid if (!image->isValid()) return; // Save current matrix glPushMatrix(); // Zoom double yscale = (gfx_arc ? scale * 1.2 : scale); glScaled(scale, yscale, 1.0); // Pan if (view_type == GFXVIEW_CENTERED) glTranslated(-(image->getWidth() * 0.5), -(image->getHeight() * 0.5), 0); // Pan to center image else if (view_type == GFXVIEW_SPRITE) glTranslated(-image->offset().x, -image->offset().y, 0); // Pan by offsets else if (view_type == GFXVIEW_HUD) { glTranslated(-160, -100, 0); // Pan to hud 'top left' glTranslated(-image->offset().x, -image->offset().y, 0); // Pan by offsets } // Enable textures glEnable(GL_TEXTURE_2D); // Update texture if needed if (update_texture) { // If the image change isn't caused by drawing, resize drawing mask if (!drawing) { if (drawing_mask) delete[] drawing_mask; drawing_mask = new bool[image->getWidth() * image->getHeight()]; memset(drawing_mask, false, image->getWidth() * image->getHeight()); } tex_image->loadImage(image, &palette); update_texture = false; } // Determine (texture)coordinates double x = (double)image->getWidth(); double y = (double)image->getHeight(); // If tiled view if (view_type == GFXVIEW_TILED) { // Draw tiled image OpenGL::setColour(255, 255, 255, 255, 0); tex_image->draw2dTiled(GetSize().x / scale, GetSize().y / scale); } else if (drag_origin.x < 0) // If not dragging { // Draw the image OpenGL::setColour(255, 255, 255, 255, 0); tex_image->draw2d(); // Draw hilight otherwise if (image_hilight && gfx_hilight_mouseover && editing_mode == 0) { OpenGL::setColour(255, 255, 255, 80, 1); tex_image->draw2d(); // Reset colour OpenGL::setColour(255, 255, 255, 255, 0); } } else // Dragging { // Draw the original OpenGL::setColour(rgba_t(0, 0, 0, 180, 0)); tex_image->draw2d(); // Draw the dragged image int off_x = (drag_pos.x - drag_origin.x) / scale; int off_y = (drag_pos.y - drag_origin.y) / scale; glTranslated(off_x, off_y, 0); OpenGL::setColour(255, 255, 255, 255, 0); tex_image->draw2d(); } // Draw brush shadow when in editing mode if (editing_mode > 0 && cursor_pos != POINT_OUTSIDE) { OpenGL::setColour(255, 255, 255, 160, 0); tex_brush->draw2d(); OpenGL::setColour(255, 255, 255, 255, 0); } // Disable textures glDisable(GL_TEXTURE_2D); // Draw outline if (gfx_show_border) { OpenGL::setColour(0, 0, 0, 64); glBegin(GL_LINE_LOOP); glVertex2d(0, 0); glVertex2d(0, y); glVertex2d(x, y); glVertex2d(x, 0); glEnd(); } // Restore previous matrix glPopMatrix(); }
/* SImage::drawImage * Draws an image on to this image at [x],[y], with blending options * set in [properties]. [pal_src] is used for the source image, and * [pal_dest] is used for the destination image, if either is * paletted *******************************************************************/ bool SImage::drawImage(SImage& img, int x_pos, int y_pos, si_drawprops_t& properties, Palette8bit* pal_src, Palette8bit* pal_dest) { // Check images if (!data || !img.data) return false; // Setup palettes if (img.has_palette || !pal_src) pal_src = &(img.palette); if (has_palette || !pal_dest) pal_dest = &palette; // Go through pixels unsigned s_stride = img.getStride(); uint8_t s_bpp = img.getBpp(); unsigned sp = 0; for (int y = y_pos; y < y_pos + img.height; y++) // Rows { // Skip out-of-bounds rows if (y < 0 || y >= height) { sp += s_stride; continue; } for (int x = x_pos; x < x_pos + img.width; x++) // Columns { // Skip out-of-bounds columns if (x < 0 || x >= width) { sp += s_bpp; continue; } // Skip if source pixel is fully transparent if ((img.type == PALMASK && img.mask[sp] == 0) || (img.type == ALPHAMAP && img.data[sp] == 0) || (img.type == RGBA && img.data[sp+3] == 0)) { sp += s_bpp; continue; } // Draw pixel if (img.type == PALMASK) { rgba_t col = pal_src->colour(img.data[sp]); col.a = img.mask[sp]; drawPixel(x, y, col, properties, pal_dest); } else if (img.type == RGBA) drawPixel(x, y, rgba_t(img.data[sp], img.data[sp+1], img.data[sp+2], img.data[sp+3]), properties, pal_dest); else if (img.type == ALPHAMAP) drawPixel(x, y, rgba_t(img.data[sp], img.data[sp], img.data[sp], img.data[sp]), properties, pal_dest); // Go to next source pixel sp += s_bpp; } } return true; }