private static void SetRowValue(TableLayoutPanel layoutPanel, Label label, string value) { if (!String.IsNullOrEmpty(value)) { label.Text = value; layoutPanel.RowStyles[layoutPanel.GetRow(label)].SizeType = SizeType.AutoSize; } else { layoutPanel.RowStyles[layoutPanel.GetRow(label)].SizeType = SizeType.Absolute; layoutPanel.RowStyles[layoutPanel.GetRow(label)].Height = 0; } layoutPanel.AutoScroll = true; }
public void TestExtenderMethods () { TableLayoutPanel p = new TableLayoutPanel (); Control c = new Button (); Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetCellPosition (c), "A1"); Assert.AreEqual (-1, p.GetColumn (c), "A2"); Assert.AreEqual (1, p.GetColumnSpan (c), "A3"); Assert.AreEqual (-1, p.GetRow (c), "A4"); Assert.AreEqual (1, p.GetRowSpan (c), "A5"); p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1)); Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6"); p.SetColumn (c, 2); Assert.AreEqual (2, p.GetColumn (c), "A7"); p.SetRow (c, 2); Assert.AreEqual (2, p.GetRow (c), "A9"); p.SetColumnSpan (c, 2); Assert.AreEqual (2, p.GetColumnSpan (c), "A8"); p.SetRowSpan (c, 2); Assert.AreEqual (2, p.GetRowSpan (c), "A10"); Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11"); // ??????? //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12"); //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13"); }
/// <summary> /// Gets a control from a position in a TableLayoutPanel. /// Note: when no control was found, each control is checked on it's own because of bugs in the layout engine from Microsoft. /// </summary> /// <param name="This">This TableLayoutPanel.</param> /// <param name="column">The column.</param> /// <param name="row">The row.</param> /// <returns>The control or <c>null</c>.</returns> public static Control GetControlFromPositionFixed(this TableLayoutPanel This, int column, int row) { #if NET35 Debug.Assert(This != null); #else Contract.Requires(This != null); #endif var result = This.GetControlFromPosition(column, row); if (result != null) { return(result); } #if DEBUG // This one's for debugging only var allControls = This.Controls.Cast <Control>().Where(c => c != null).ToDictionary(control => control, control => Tuple.Create(This.GetColumn(control), This.GetRow(control))); #endif return(( from control in This.Controls.Cast <Control>().Where(c => c != null) where This.GetColumn(control) == column && This.GetRow(control) == row select(control) ).FirstOrDefault()); }
// Set a shader stage's resources and values private void SetShaderState(FetchTexture[] texs, FetchBuffer[] bufs, GLPipelineState state, GLPipelineState.ShaderStage stage, TableLayoutPanel table, Label shader, TreelistView.TreeListView textures, TreelistView.TreeListView samplers, TreelistView.TreeListView cbuffers, TreelistView.TreeListView subs, TreelistView.TreeListView readwrites) { ShaderReflection shaderDetails = stage.ShaderDetails; var mapping = stage.BindpointMapping; if (stage.Shader == ResourceId.Null) shader.Text = "Unbound"; else shader.Text = stage.stage.Str(APIPipelineStateType.OpenGL) + " Shader " + stage.Shader.ToString(); // disabled since entry function is always main, and filenames have no names, so this is useless. /* if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc != "" && shaderDetails.DebugInfo.files.Length > 0) shader.Text = shaderDetails.DebugInfo.entryFunc + "()" + " - " + Path.GetFileName(shaderDetails.DebugInfo.files[0].filename); */ int vs = 0; int vs2 = 0; // simultaneous update of resources and samplers vs = textures.VScrollValue(); textures.BeginUpdate(); textures.Nodes.Clear(); vs2 = samplers.VScrollValue(); samplers.BeginUpdate(); samplers.Nodes.Clear(); if (state.Textures != null) { for (int i = 0; i < state.Textures.Length; i++) { var r = state.Textures[i]; var s = state.Samplers[i]; ShaderResource shaderInput = null; BindpointMap map = null; if (shaderDetails != null) { foreach (var bind in shaderDetails.Resources) { if (bind.IsSRV && !bind.IsReadWrite && mapping.Resources[bind.bindPoint].bind == i) { shaderInput = bind; map = mapping.Resources[bind.bindPoint]; } } } bool filledSlot = (r.Resource != ResourceId.Null); bool usedSlot = (shaderInput != null && map.used); // show if if (usedSlot || // it's referenced by the shader - regardless of empty or not (showDisabled.Checked && !usedSlot && filledSlot) || // it's bound, but not referenced, and we have "show disabled" (showEmpty.Checked && !filledSlot) // it's empty, and we have "show empty" ) { // do texture { string slotname = i.ToString(); if (shaderInput != null && shaderInput.name != "") slotname += ": " + shaderInput.name; UInt32 w = 1, h = 1, d = 1; UInt32 a = 1; string format = "Unknown"; string name = "Shader Resource " + r.Resource.ToString(); string typename = "Unknown"; object tag = null; if (!filledSlot) { name = "Empty"; format = "-"; typename = "-"; w = h = d = a = 0; } // check to see if it's a texture for (int t = 0; t < texs.Length; t++) { if (texs[t].ID == r.Resource) { w = texs[t].width; h = texs[t].height; d = texs[t].depth; a = texs[t].arraysize; format = texs[t].format.ToString(); name = texs[t].name; typename = texs[t].resType.Str(); if (texs[t].format.special && (texs[t].format.specialFormat == SpecialFormat.D24S8 || texs[t].format.specialFormat == SpecialFormat.D32S8) ) { if (r.DepthReadChannel == 0) format += " Depth-Read"; else if (r.DepthReadChannel == 1) format += " Stencil-Read"; } else if ( r.Swizzle[0] != TextureSwizzle.Red || r.Swizzle[1] != TextureSwizzle.Green || r.Swizzle[2] != TextureSwizzle.Blue || r.Swizzle[3] != TextureSwizzle.Alpha) { format += String.Format(" swizzle[{0}{1}{2}{3}]", r.Swizzle[0].Str(), r.Swizzle[1].Str(), r.Swizzle[2].Str(), r.Swizzle[3].Str()); } tag = texs[t]; } } var node = textures.Nodes.Add(new object[] { slotname, name, typename, w, h, d, a, format }); node.Image = global::renderdocui.Properties.Resources.action; node.HoverImage = global::renderdocui.Properties.Resources.action_hover; node.Tag = tag; if (!filledSlot) EmptyRow(node); if (!usedSlot) InactiveRow(node); } // do sampler { string slotname = i.ToString(); if (shaderInput != null && shaderInput.name.Length > 0) slotname += ": " + shaderInput.name; string borderColor = s.BorderColor[0].ToString() + ", " + s.BorderColor[1].ToString() + ", " + s.BorderColor[2].ToString() + ", " + s.BorderColor[3].ToString(); string addressing = ""; string addPrefix = ""; string addVal = ""; string[] addr = { s.AddressS, s.AddressT, s.AddressR }; // arrange like either STR: WRAP or ST: WRAP, R: CLAMP for (int a = 0; a < 3; a++) { string prefix = "" + "STR"[a]; if (a == 0 || addr[a] == addr[a - 1]) { addPrefix += prefix; } else { addressing += addPrefix + ": " + addVal + ", "; addPrefix = prefix; } addVal = addr[a]; } addressing += addPrefix + ": " + addVal; if (s.UseBorder) addressing += String.Format("<{0}>", borderColor); if (r.ResType == ShaderResourceType.TextureCube || r.ResType == ShaderResourceType.TextureCubeArray) { addressing += s.SeamlessCube ? " Seamless" : " Non-Seamless"; } string minfilter = s.MinFilter; if (s.MaxAniso > 1) minfilter += String.Format(" Aniso{0}x", s.MaxAniso); if (s.UseComparison) minfilter = String.Format("{0}", s.Comparison); var node = samplers.Nodes.Add(new object[] { slotname, addressing, minfilter, s.MagFilter, (s.MinLOD == -float.MaxValue ? "0" : s.MinLOD.ToString()) + " - " + (s.MaxLOD == float.MaxValue ? "FLT_MAX" : s.MaxLOD.ToString()), s.MipLODBias.ToString() }); if (!filledSlot) EmptyRow(node); if (!usedSlot) InactiveRow(node); } } } } textures.EndUpdate(); textures.NodesSelection.Clear(); textures.SetVScrollValue(vs); samplers.EndUpdate(); samplers.NodesSelection.Clear(); samplers.SetVScrollValue(vs2); vs = cbuffers.VScrollValue(); cbuffers.BeginUpdate(); cbuffers.Nodes.Clear(); if (shaderDetails != null) { UInt32 i = 0; foreach (var shaderCBuf in shaderDetails.ConstantBlocks) { int bindPoint = stage.BindpointMapping.ConstantBlocks[i].bind; GLPipelineState.Buffer b = null; if (bindPoint >= 0 && bindPoint < state.UniformBuffers.Length) b = state.UniformBuffers[bindPoint]; bool filledSlot = !shaderCBuf.bufferBacked || (b != null && b.Resource != ResourceId.Null); bool usedSlot = stage.BindpointMapping.ConstantBlocks[i].used; // show if if (usedSlot || // it's referenced by the shader - regardless of empty or not (showDisabled.Checked && !usedSlot && filledSlot) || // it's bound, but not referenced, and we have "show disabled" (showEmpty.Checked && !filledSlot) // it's empty, and we have "show empty" ) { ulong offset = 0; ulong length = 0; int numvars = shaderCBuf.variables.Length; string slotname = "Uniforms"; string name = ""; string sizestr = String.Format("{0} Variables", numvars); string byterange = ""; if (!filledSlot) { name = "Empty"; length = 0; } if (b != null) { slotname = String.Format("{0}: {1}", bindPoint, shaderCBuf.name); name = "UBO " + b.Resource.ToString(); offset = b.Offset; length = b.Size; for (int t = 0; t < bufs.Length; t++) { if (bufs[t].ID == b.Resource) { name = bufs[t].name; if (length == 0) length = bufs[t].length; } } sizestr = String.Format("{0} Variables, {1} bytes", numvars, length); byterange = String.Format("{0} - {1}", offset, offset + length); } var node = cbuffers.Nodes.Add(new object[] { slotname, name, byterange, sizestr }); node.Image = global::renderdocui.Properties.Resources.action; node.HoverImage = global::renderdocui.Properties.Resources.action_hover; node.Tag = i; if (!filledSlot) EmptyRow(node); if (!usedSlot) InactiveRow(node); } i++; } } cbuffers.EndUpdate(); cbuffers.NodesSelection.Clear(); cbuffers.SetVScrollValue(vs); vs = subs.VScrollValue(); subs.BeginUpdate(); subs.Nodes.Clear(); { UInt32 i = 0; foreach (var subval in stage.Subroutines) { subs.Nodes.Add(new object[] { i.ToString(), subval.ToString() }); i++; } } subs.EndUpdate(); subs.NodesSelection.Clear(); subs.SetVScrollValue(vs); { subs.Visible = subs.Parent.Visible = (stage.Subroutines.Length > 0); int row = table.GetRow(subs.Parent); if (row >= 0 && row < table.RowStyles.Count) { if (stage.Subroutines.Length > 0) table.RowStyles[row].Height = table.RowStyles[1].Height; else table.RowStyles[row].Height = 0; } } vs = readwrites.VScrollValue(); readwrites.BeginUpdate(); readwrites.Nodes.Clear(); if (shaderDetails != null) { UInt32 i = 0; foreach (var res in shaderDetails.Resources) { int bindPoint = stage.BindpointMapping.Resources[i].bind; bool atomic = false; bool ssbo = false; bool image = false; if (!res.IsReadWrite) { i++; continue; } GLPipelineState.Buffer bf = null; GLPipelineState.ImageLoadStore im = null; ResourceId id = ResourceId.Null; if (res.IsTexture) { image = true; if (bindPoint >= 0 && bindPoint < state.Images.Length) { im = state.Images[bindPoint]; id = state.Images[bindPoint].Resource; } } else { if (res.variableType.descriptor.rows == 1 && res.variableType.descriptor.cols == 1 && res.variableType.descriptor.type == VarType.UInt) { atomic = true; if (bindPoint >= 0 && bindPoint < state.AtomicBuffers.Length) { bf = state.AtomicBuffers[bindPoint]; id = state.AtomicBuffers[bindPoint].Resource; } } else { ssbo = true; if (bindPoint >= 0 && bindPoint < state.ShaderStorageBuffers.Length) { bf = state.ShaderStorageBuffers[bindPoint]; id = state.ShaderStorageBuffers[bindPoint].Resource; } } } bool filledSlot = id != ResourceId.Null; bool usedSlot = stage.BindpointMapping.Resources[i].used; // show if if (usedSlot || // it's referenced by the shader - regardless of empty or not (showDisabled.Checked && !usedSlot && filledSlot) || // it's bound, but not referenced, and we have "show disabled" (showEmpty.Checked && !filledSlot) // it's empty, and we have "show empty" ) { string binding = image ? "Image" : atomic ? "Atomic" : ssbo ? "SSBO" : "Unknown"; string slotname = String.Format("{0}: {1}", bindPoint, res.name); string name = ""; string dimensions = ""; string format = "-"; string access = "Read/Write"; if (im != null) { if (im.readAllowed && !im.writeAllowed) access = "Read-Only"; if (!im.readAllowed && im.writeAllowed) access = "Write-Only"; format = im.Format.ToString(); } object tag = null; // check to see if it's a texture for (int t = 0; t < texs.Length; t++) { if (texs[t].ID == id) { if (texs[t].dimension == 1) { if(texs[t].arraysize > 1) dimensions = String.Format("{0}[{1}]", texs[t].width, texs[t].arraysize); else dimensions = String.Format("{0}", texs[t].width); } else if (texs[t].dimension == 2) { if (texs[t].arraysize > 1) dimensions = String.Format("{0}x{1}[{2}]", texs[t].width, texs[t].height, texs[t].arraysize); else dimensions = String.Format("{0}x{1}", texs[t].width, texs[t].height); } else if (texs[t].dimension == 3) { dimensions = String.Format("{0}x{1}x{2}", texs[t].width, texs[t].height, texs[t].depth); } name = texs[t].name; tag = texs[t]; } } // if not a texture, it must be a buffer for (int t = 0; t < bufs.Length; t++) { if (bufs[t].ID == id) { ulong offset = 0; ulong length = bufs[t].length; if (bf != null && bf.Size > 0) { offset = bf.Offset; length = bf.Size; } if(offset > 0) dimensions = String.Format("{0} bytes at offset {1} bytes", length, offset); else dimensions = String.Format("{0} bytes", length); name = bufs[t].name; tag = new ReadWriteTag(i, bufs[t]); } } if (!filledSlot) { name = "Empty"; dimensions = "-"; access = "-"; } var node = readwrites.Nodes.Add(new object[] { binding, slotname, name, dimensions, format, access }); node.Image = global::renderdocui.Properties.Resources.action; node.HoverImage = global::renderdocui.Properties.Resources.action_hover; node.Tag = tag; if (!filledSlot) EmptyRow(node); if (!usedSlot) InactiveRow(node); } i++; } } readwrites.EndUpdate(); readwrites.NodesSelection.Clear(); readwrites.SetVScrollValue(vs); { readwrites.Visible = readwrites.Parent.Visible = (readwrites.Nodes.Count > 0); int row = table.GetRow(readwrites.Parent); if (row >= 0 && row < table.RowStyles.Count) { if (readwrites.Nodes.Count > 0) table.RowStyles[row].Height = table.RowStyles[1].Height; else table.RowStyles[row].Height = 0; } } }
// gb_init_heigh_percent : dung voi thu tu rowstyle cua TLP !!!!! static public void CollapseGroupBox(GroupBox collapse_gb , GroupBox[] other_gb, TableLayoutPanel TLP_Parent , int RowStyleIndex, UserControl UC, List<KeyValuePair<GroupBox,float>> gb_init_heigh_percent) { int CollapseSize = 30; int CollapsedGB = 1; // so gb da collapse int GBHeigh_Pixel = collapse_gb.Height; if (collapse_gb.Text.Contains("[+]")) // Expand { for (int i = 0; i < gb_init_heigh_percent.Count; i++) { TLP_Parent.RowStyles[i].SizeType = SizeType.Percent; if (gb_init_heigh_percent[i].Key.Text.Contains("[-]") || i == RowStyleIndex) // gb dang expand hoac la gb duoc click { TLP_Parent.RowStyles[i].Height = gb_init_heigh_percent[i].Value; } else // cac gb dang collapse { TLP_Parent.RowStyles[i].SizeType = SizeType.Absolute; TLP_Parent.RowStyles[i].Height = CollapseSize; } } collapse_gb.Text = collapse_gb.Text.Replace("[+]", "[-]"); } else // Collapse { for (int i = 0; i < other_gb.Length; i++) { if (other_gb[i].Text.Contains("[+]")) { CollapsedGB++; } } if (CollapsedGB < gb_init_heigh_percent.Count) // o cho collapse gb cuoi cung { TLP_Parent.RowStyles[RowStyleIndex].SizeType = SizeType.Absolute; TLP_Parent.RowStyles[RowStyleIndex].Height = CollapseSize; for (int i = 0; i < other_gb.Length; i++) { if (other_gb[i].Text.Contains("[-]")) // cac gb dang expand { // (100% - (số gb đã collaspe * collapse size)) / ( so gb con lai - so gb đã collaspe = so gb chua collapse) TLP_Parent.RowStyles[TLP_Parent.GetRow(other_gb[i])].SizeType = SizeType.Percent; TLP_Parent.RowStyles[TLP_Parent.GetRow(other_gb[i])].Height += (100 - (CollapsedGB * CollapseSize)) / (other_gb.Length - CollapsedGB + 1); } } for (int i = 0; i < other_gb.Length; i++) { if (other_gb[i].Text.Contains("[+]")) // cac gb dang collapse { TLP_Parent.RowStyles[TLP_Parent.GetRow(other_gb[i])].SizeType = SizeType.Absolute; TLP_Parent.RowStyles[TLP_Parent.GetRow(other_gb[i])].Height = CollapseSize; } } collapse_gb.Text = collapse_gb.Text.Replace("[-]", "[+]"); } } }
private void killedPieces_MouseClick(object sender, MouseEventArgs e) { if (pawnChangable) { Control c = (Control)sender; TableLayoutPanel teamBox = new TableLayoutPanel(); if (currentState.getMyTeam() == (int)team.black) teamBox = this.blackTeamPanel; else if (currentState.getMyTeam() == (int)team.white) teamBox = this.whiteTeamPanel; int index = (teamBox.GetRow(c) * 2) + teamBox.GetColumn(c); if (gameboard.getDead(currentState.getMyTeam()).Count() > index) { Piece currentPiece = gameboard.getDead(currentState.getMyTeam())[index]; if (gameboard.tradePawn(previousPiece, currentPiece)) { if (gameboard.checkChessMate(currentState.getMyTeam()) == (int)moveResult.chessMate) { DialogResult result = MessageBox.Show("Chessmate! You win.\n\nPlay again?", "Chess - Message", MessageBoxButtons.YesNo); promptNewGame(result); return; } pawnChangable = false; previousPiece = null; AIOpponent.Move(gameboard, currentState); updateBoard(); if (gameboard.checkChessMate(currentState.getOpponentTeam()) == (int)moveResult.chessMate) { DialogResult result = MessageBox.Show("Chessmate! You loose.\n\nPlay again?", "Chess - Message", MessageBoxButtons.YesNo); promptNewGame(result); return; } } } } }