void AddOverlay(ref Gdk.Pixbuf icon, Gdk.Pixbuf overlay) { Gdk.Pixbuf cached = Context.GetComposedIcon(icon, overlay); if (cached != null) { icon = cached; return; } int dx = 2; int dy = 2; Gdk.Pixbuf res = new Gdk.Pixbuf(icon.Colorspace, icon.HasAlpha, icon.BitsPerSample, icon.Width + dx, icon.Height + dy); res.Fill(0); icon.CopyArea(0, 0, icon.Width, icon.Height, res, 0, 0); overlay.Composite(res, res.Width - overlay.Width, res.Height - overlay.Height, overlay.Width, overlay.Height, res.Width - overlay.Width, res.Height - overlay.Height, 1, 1, Gdk.InterpType.Bilinear, 255); Context.CacheComposedIcon(icon, overlay, res); icon = res; }
//caller should check that sizes match public static Gdk.Pixbuf MergeIcons(Gdk.Pixbuf icon1, Gdk.Pixbuf icon2) { if (icon2 == null) { return(icon1); } if (icon1 == null) { return(icon2); } Gdk.Pixbuf res = new Gdk.Pixbuf(icon1.Colorspace, icon1.HasAlpha, icon1.BitsPerSample, icon1.Width, icon1.Height); res.Fill(0); icon1.CopyArea(0, 0, icon1.Width, icon1.Height, res, 0, 0); icon2.Composite(res, 0, 0, icon2.Width, icon2.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); var icon1_2x = Get2xIconVariant(icon1); var icon2_2x = Get2xIconVariant(icon2); if (icon1_2x != null || icon2_2x != null) { if (icon1_2x == null) { icon1_2x = ScaleIcon(icon1, icon1.Width * 2, icon1.Height * 2); } if (icon2_2x == null) { icon2_2x = ScaleIcon(icon2, icon2.Width * 2, icon2.Height * 2); } var res2x = MergeIcons(icon1_2x, icon2_2x); Set2xIconVariant(res, res2x); } return(res); }
private void MarkImage(Token t) { if (t == null) { originalImageArea.Image = originalImage; return; } Gdk.Pixbuf originalMarked = originalImage.Copy(); // We tint the copy in red. originalMarked = originalMarked.CompositeColorSimple(originalMarked.Width, originalMarked.Height, Gdk.InterpType.Bilinear, 100, 1, 0xAAAAAA, 0xAAAAAA); // Over the red tinted copy, we place the piece we want to be // normal. originalImage.CopyArea(t.Left, t.Top, t.Width, t.Height, originalMarked, t.Left, t.Top); originalImageArea.Image = originalMarked; }
public ImageTexture(Stream input) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(input); uint width = (uint)pixbuf.Width; uint height = (uint)pixbuf.Height; // Round to next power-of-two isn't needed with newer OpenGL versions if (!GlHelper.HasExtension("GL_ARB_texture_non_power_of_two")) { width = NextPowerOfTwo((uint)width); height = NextPowerOfTwo((uint)height); } Gdk.Pixbuf target = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, (int)width, (int)height); pixbuf.CopyArea(0, 0, pixbuf.Width, pixbuf.Height, target, 0, 0); ImageWidth = (float)pixbuf.Width; ImageHeight = (float)pixbuf.Height; this.width = (uint)target.Width; this.height = (uint)target.Height; this.pixbuf = target; }
//caller should check null and that sizes match static Gdk.Pixbuf MergeIcons(Gdk.Pixbuf icon1, Gdk.Pixbuf icon2) { Gdk.Pixbuf res = new Gdk.Pixbuf(icon1.Colorspace, icon1.HasAlpha, icon1.BitsPerSample, icon1.Width, icon1.Height); res.Fill(0); icon1.CopyArea(0, 0, icon1.Width, icon1.Height, res, 0, 0); icon2.Composite(res, 0, 0, icon2.Width, icon2.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); return(res); }
public static Gdk.Pixbuf AddIconOverlay(Gdk.Pixbuf target, Gdk.Pixbuf overlay) { Gdk.Pixbuf res = new Gdk.Pixbuf(target.Colorspace, target.HasAlpha, target.BitsPerSample, target.Width, target.Height); res.Fill(0); target.CopyArea(0, 0, target.Width, target.Height, res, 0, 0); overlay.Composite(res, 0, 0, overlay.Width, overlay.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); return(res); }
public override void Execute(SurfaceReceiver receiver) { int x, y; int tx, ty; int width, height; Gdk.Pixbuf pixbuf; Gdk.Rectangle[] rects; Gdk.Rectangle clippedRect; if (codecID != CODEC_ID_REMOTEFX) { return; } RfxMessage rfxMsg = receiver.rfx.ParseMessage(bitmapData, bitmapDataLength); x = y = 0; width = height = 64; rects = new Gdk.Rectangle[rfxMsg.RectCount]; int count = 0; while (rfxMsg.HasNextRect()) { rfxMsg.GetNextRect(ref x, ref y, ref width, ref height); tx = x + destLeft; ty = y + destTop; rects[count++] = new Gdk.Rectangle(tx, ty, width, height); } while (rfxMsg.HasNextTile()) { rfxMsg.GetNextTile(buffer, ref x, ref y); tx = x + destLeft; ty = y + destTop; Gdk.Rectangle tileRect = new Gdk.Rectangle(tx, ty, 64, 64); foreach (Gdk.Rectangle rect in rects) { rect.Intersect(tileRect, out clippedRect); if (!clippedRect.IsEmpty) { pixbuf = new Gdk.Pixbuf(buffer, Gdk.Colorspace.Rgb, true, 8, 64, 64, 64 * 4); pixbuf.CopyArea(0, 0, clippedRect.Width, clippedRect.Height, receiver.surface, clippedRect.X, clippedRect.Y); receiver.InvalidateRect(clippedRect.X, clippedRect.Y, clippedRect.Width, clippedRect.Height); } } } }
public override void Execute(SurfaceReceiver receiver) { int x, y; int tx, ty; int width, height; Gdk.Pixbuf pixbuf; Gdk.Rectangle[] rects; Gdk.Rectangle clippedRect; if (codecID != CODEC_ID_REMOTEFX) return; RfxMessage rfxMsg = receiver.rfx.ParseMessage(bitmapData, bitmapDataLength); x = y = 0; width = height = 64; rects = new Gdk.Rectangle[rfxMsg.RectCount]; int count = 0; while (rfxMsg.HasNextRect()) { rfxMsg.GetNextRect(ref x, ref y, ref width, ref height); tx = x + destLeft; ty = y + destTop; rects[count++] = new Gdk.Rectangle(tx, ty, width, height); } while (rfxMsg.HasNextTile()) { rfxMsg.GetNextTile(buffer, ref x, ref y); tx = x + destLeft; ty = y + destTop; Gdk.Rectangle tileRect = new Gdk.Rectangle(tx, ty, 64, 64); foreach (Gdk.Rectangle rect in rects) { rect.Intersect(tileRect, out clippedRect); if (!clippedRect.IsEmpty) { pixbuf = new Gdk.Pixbuf(buffer, Gdk.Colorspace.Rgb, true, 8, 64, 64, 64 * 4); pixbuf.CopyArea(0, 0, clippedRect.Width, clippedRect.Height, receiver.surface, clippedRect.X, clippedRect.Y); receiver.InvalidateRect(clippedRect.X, clippedRect.Y, clippedRect.Width, clippedRect.Height); } } } }
private void InitializeColorComboBox(Gtk.ComboBox colorChooser, ObservableCollection <FileNodeColorViewModel> colors, MenuLayoutViewModel dataContext) { colorChooser.SetValue(IFakeDependencyObjectHelpers.DataContextPropertyName, dataContext); colorChooser.TooltipText = MenuLayoutViewModel.ColorTip; foreach (var color in colors) { var pixbufColor = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 14, 14); var uintColor = (uint)((color.Fill.Red & 0xFF) << 24) | (uint)((color.Fill.Green & 0xFF) << 16) | (uint)((color.Fill.Blue & 0xFF) << 8) | 0xFF; pixbufColor.Fill(uintColor); var pixbuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 16, 16); pixbuf.Fill(0xFF); // black background pixbufColor.CopyArea(0, 0, 14, 14, pixbuf, 1, 1); ColorPixbufs[color.IntvColor] = pixbuf; } Gtk.CellRenderer cellRenderer = new Gtk.CellRendererPixbuf() { Xalign = 0 }; colorChooser.PackStart(cellRenderer, false); colorChooser.SetCellDataFunc(cellRenderer, (l, e, m, i) => VisualHelpers.CellImageRenderer <FileNodeColorViewModel>(l, e, m, i, c => ColorPixbufs[c.IntvColor])); cellRenderer = new Gtk.CellRendererCombo() { Xalign = 0, Xpad = 4 }; colorChooser.PackEnd(cellRenderer, true); colorChooser.SetCellDataFunc(cellRenderer, (l, e, m, i) => VisualHelpers.CellTextRenderer <FileNodeColorViewModel>(l, e, m, i, c => c.Name)); var colorListStore = new Gtk.ListStore(typeof(FileNodeColorViewModel)); colorListStore.SynchronizeCollection(colors); colorChooser.Model = colorListStore; MenuLayoutCommandGroup.SetColorCommand.CanExecuteChanged += HandleCanExecuteSetColorChanged; }
public ImageTexture(Stream input) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(input); uint width = (uint)pixbuf.Width; uint height = (uint)pixbuf.Height; // Round to next power-of-two isn't needed with newer OpenGL versions if (!GlHelper.HasExtension("GL_ARB_texture_non_power_of_two")) { width = NextPowerOfTwo((uint)width); height = NextPowerOfTwo((uint)height); } Gdk.Pixbuf target = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, (int)width, (int)height); pixbuf.CopyArea(0, 0, pixbuf.Width, pixbuf.Height, target, 0, 0); ImageWidth = (float) pixbuf.Width; ImageHeight = (float) pixbuf.Height; this.width = (uint)target.Width; this.height = (uint)target.Height; this.pixbuf = target; }
// window is the scrolled window; should be named apropriately eventually public JsonClass(Gtk.Container window, Gtk.Image image, myListStore myListstore) { Gdk.Pixbuf tileSet = image.Pixbuf, scaled = image.Pixbuf; int height = tileSet.Height, width = tileSet.Width; // a treestore so the tiles with subtiles can be expanded, eventually also categories that are expandable Gtk.TreeStore myListStore = new Gtk.TreeStore(typeof(string), typeof(int), typeof(string), typeof(Gdk.Pixbuf)); tile_info_nested tile_info = new tile_info_nested(); // should have a better name eventually // should either be chosen by user or maybe the folder where the tileset resides StreamReader streamReader = new StreamReader(@"/home/gervinius/Pragramming/Mono/jsonTest/jsonTest/tile_config.json"); tile_info_nested deserializedJsonFile = JsonConvert.DeserializeObject <tile_info_nested> (streamReader.ReadToEnd()); streamReader.Close(); int value, tileWidthHeight = 16; if (deserializedJsonFile.tile_info [0].TryGetValue("height", out value)) { tileWidthHeight = value; Console.WriteLine(tileWidthHeight); } scaled = scaled.ScaleSimple(tileWidthHeight, tileWidthHeight, Gdk.InterpType.Bilinear); // temp solution; should look for a more elegant solution //this copies the list from the json object list to another list. Could be a better solution someday tile_info.tiles = new List <Json_tile_class> (deserializedJsonFile.tiles); //checks if tile has subtiles and adds them to a list for (int i = 0; i < tile_info.tiles.Count; i++) { if (tile_info.tiles [i].multitile == true) { //just copy the list with subtiles tile_info.tiles [i].additional_tiles = new List <Json_tile_class> (deserializedJsonFile.tiles[i].additional_tiles); } } //reads the tileset image and copies each individual tile to a pixbuf; should be a seperate method eventually for (int i = 0; i < height / tileWidthHeight; i++) { for (int h = 0; h < width / tileWidthHeight; h++) { tile_info.lstPixbuf.Add(scaled.Copy()); //hack to initialize a empty pixbuf at the correct index in the list, there may be a more performant solution tileSet.CopyArea(h * tileWidthHeight, i * tileWidthHeight, tileWidthHeight, tileWidthHeight, tile_info.lstPixbuf[i * 16 + h], 0, 0); //copy the pixels that reperesent one tile to the pixbuf at the lists index } } //checks whether the tile has a bg or fg image (or both) for (int i = 0; i < tile_info.tiles.Count; i++) { Gdk.Pixbuf myListstoreImage = scaled.Copy(); // initialize a pixbuf with 32x32 pixels;; could be in the class eventually if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0) // some persons have used the value -1 to mark a nonexisting fg- or bg-image { tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value]; myListstoreImage = tile_info.tiles [i].fg_image; } else if (tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0) { tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value]; myListstoreImage = tile_info.tiles [i].bg_image; } else if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0 && tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0) { tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value]; tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value]; // this merges background and foreground tile_info.tiles [i].bg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1); tile_info.tiles [i].fg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1); } // if the tile object has additional tiles ... if (tile_info.tiles [i].multitile == true) { // create an expandable treeiter Gtk.TreeIter iter = myListStore.AppendValues(tile_info.tiles[i].id); // category name is the maintiles name, could be changed later //append the PARENT TILE to the treestore myListStore.AppendValues(iter, tile_info.tiles [i].id, 1, "test1", myListstoreImage); // look through each subtile and add the foreground or background image to the liststore for (int x = 0; x < tile_info.tiles[i].additional_tiles.Count; x++) { if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0) { tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value]; myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].fg_image); } else if (tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0) { tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value]; myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].bg_image); // ToDo:: merge fg and bg } else if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0 && tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0) { tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value]; tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value]; myListStore.AppendValues(tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].fg_image); } } } else { // append the tile at index i to the liststore myListStore.AppendValues(tile_info.tiles [i].id, "test", "test1", myListstoreImage); } } myListstore.returnTV().Model = myListStore; }
/// <summary> /// Handles the start of processing of a new node. /// </summary> /// <param name="sender"> /// A <see cref="System.Object"/> /// </param> /// <param name="args"> /// A <see cref="EventArgs"/> /// </param> private void OnControllerTokenChecked(object sender, TokenCheckedArgs args) { Application.Invoke(sender, args, delegate(object resender, EventArgs _args) { TokenCheckedArgs a = _args as TokenCheckedArgs; if (!sequencingFinished) { currentToken = a.CurrentToken; FloatBitmap sequenceImage; if (a.LastSequence != null) { TokenSequence joinSeq = new TokenSequence(a.LastSequence); lastToken = joinSeq.Last; joinSeq.Append(currentToken); Token joinedToken = Token.Join(joinSeq, ""); sequenceImage = joinedToken.Image; } else { sequenceImage = currentToken.Image; lastToken = null; } // We add a border to the orginal image. Gdk.Pixbuf sequencePixbuf = sequenceImage.CreatePixbuf(); Gdk.Pixbuf drawnImage = new Gdk.Pixbuf(sequencePixbuf.Colorspace, false, 8, sequencePixbuf.Width + 10, sequencePixbuf.Height + 10); drawnImage.Fill(0xFFFFFFFF); sequencePixbuf.CopyArea(0, 0, sequencePixbuf.Width, sequencePixbuf.Height, drawnImage, 5, 5); if (lastToken != null) { uint color; if (currentToken.CloseFollows(lastToken)) { color = 0x00FF00; sequencingStepResultLbl.Markup = String.Format("<b>Sí, el símbolo «{0}» se añadirá a la secuencia actual</b>", currentToken.Text); } else { color = 0xFF0000; sequencingStepResultLbl.Markup = String.Format("<b>No, «{0}» no puede ser considerado parte de la secuencia ({1})</b>", currentToken.Text, a.LastSequence.ToString()); } Gdk.Pixbuf markedImage = drawnImage.Copy(); // We paint the image of the color markedImage = markedImage.CompositeColorSimple(markedImage.Width, markedImage.Height, Gdk.InterpType.Nearest, 100, 1, color, color); // We are going to mark the image of the to symbols being considered // with their baselines. int min = int.MaxValue; foreach (Token t in a.LastSequence) { if (t.Top < min) { min = t.Top; } } int offset = Math.Min(min, currentToken.Top); int lastBaseline = lastToken.Baseline - offset; int currentBaseline = currentToken.Baseline - offset; markedImage.CopyArea(0, lastBaseline, markedImage.Width, 5, drawnImage, 0, lastBaseline); markedImage.CopyArea(0, currentBaseline, markedImage.Width, 5, drawnImage, 0, currentBaseline); } baselineImageArea.Image = drawnImage; } if (controller.StepMode == ControllerStepMode.StepByStep) { tokenizingNextButtonsAlign.Sensitive = true; } }); }
/// <summary> /// Handles the controller's SequenceBeingMatched event. /// </summary> /// <param name="sender"> /// A <see cref="System.Object"/> /// </param> /// <param name="quenceBeingMatchedArgs"> /// A <see cref="Se"/> /// </param> private void OnControllerSequenceBeingMatched(object sender, SequenceBeingMatchedArgs args) { Application.Invoke(sender, args, delegate(object resender, EventArgs _args) { SequenceBeingMatchedArgs a = _args as SequenceBeingMatchedArgs; Gdk.Pixbuf sequenceImage = a.JoinedToken.Image.CreatePixbuf(); Gdk.Pixbuf drawnImage = sequenceNodeImage.Copy(); sequenceImage.CopyArea(0, 0, sequenceImage.Width, sequenceImage.Height, drawnImage, 0, 0); sequenceMatchingImageArea.Image = drawnImage; TreeIter iter; tokenizingRulesTV.Model.GetIterFirst(out iter); TreePath path = tokenizingRulesTV.Model.GetPath(iter); tokenizingRulesTV.Selection.UnselectAll(); string ruleName; do { ruleName = tokenizingRulesTV.Model.GetValue(iter, 0) as string; if (ruleName == a.MatchingRule.Name) { tokenizingRulesTV.Selection.SelectPath(path); tokenizingRulesTV.ScrollToCell(path, tokenizingRulesTV.Columns[0], true, 0.5f, 0); break; } path.Next(); }while(tokenizingRulesTV.Model.GetIter(out iter, path)); if (a.Found) { matchingResultLbl.Markup = String.Format("<b>Sí, se le asigna el item «{0}» a la secuencia actual</b>", a.JoinedToken.Type); } else { matchingResultLbl.Markup = String.Format("<b>No, la regla actual no concuerda con la secuencia</b>"); } // Activate the buttons if necessary. if (controller.StepMode == ControllerStepMode.StepByStep) { tokenizingNextButtonsAlign.Sensitive = true; } }); }