Skip to content

Commit

Permalink
Branches render independantly, reusing the listbox control.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammi-Husky committed Jan 2, 2015
1 parent f73509a commit 6082230
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 44 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
7 changes: 5 additions & 2 deletions BrawlCmd/BrawlCmd.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -27,7 +27,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
Expand Down Expand Up @@ -108,6 +108,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '_DEBUG|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -117,6 +118,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '_DEBUG|Itanium'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -126,6 +128,7 @@
<PlatformTarget>Itanium</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion BrawlCmd/app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
1 change: 1 addition & 0 deletions BrawlLib/BrawlLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Prefer32Bit>false</Prefer32Bit>
<DefineConstants>
</DefineConstants>
<CodeAnalysisIgnoreGeneratedCode>false</CodeAnalysisIgnoreGeneratedCode>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
28 changes: 26 additions & 2 deletions BrawlLib/SSBB/ResourceNodes/Modules/Relocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public bool
private RelCommand _command;

[Browsable(false)]
public PPCOpCode Code { get { return RawValue; } }
public PPCOpCode Code
{
get
{
return RawValue;
}
}

[Browsable(false)]
public Relocation Target { get { return _target; } set { SetTarget(value); } }
Expand All @@ -64,7 +70,21 @@ public uint RawValue
hexBox1.ByteProvider.ReadByte(t + 1),
hexBox1.ByteProvider.ReadByte(t + 0),
};
return BitConverter.ToUInt32(bytes, 0);

uint val = BitConverter.ToUInt32(bytes, 0);
if ((PPCOpCode)val is PPCBranch && !((PPCOpCode)val is PPCblr || (PPCOpCode)val is PPCbctr))
{
PPCBranch branchOp = (PPCBranch)val;
int index =
!branchOp.Absolute ?
(_index * 4 + branchOp.DataOffset).RoundDown(4) / 4 :
-1;
Relocation r = _section.GetRelocationAtIndex(index);
if(!r.Branched.Contains(this))
r.Branched.Add(this);
}

return val;
}

This comment has been minimized.

Copy link
@Sammi-Husky

Sammi-Husky Jan 2, 2015

Author Collaborator

No doubt there is a better place to put this code..but this will suffice for now.

}
set
Expand Down Expand Up @@ -118,6 +138,7 @@ private void SetCommand(RelCommand command)
_command._parentRelocation = this;
SetTarget(_command.GetTargetRelocation());
}

}

private void SetTarget(Relocation target)
Expand All @@ -138,6 +159,9 @@ private void SetTarget(Relocation target)
public BindingList<Relocation> Linked { get { return _linked; } }
private BindingList<Relocation> _linked = new BindingList<Relocation>();

public BindingList<Relocation> Branched { get { return _branched; } }
private BindingList<Relocation> _branched = new BindingList<Relocation>();

internal void Link(Relocation r)
{
_linked.Add(r);
Expand Down
54 changes: 21 additions & 33 deletions BrawlLib/System/Windows/Controls/Hex Editor/HexBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,36 +2569,23 @@ void PaintColumnSeparator(Graphics g)

void GetBrushes(Relocation r, long remainder, ref Brush foreColor, ref Brush backColor)
{
foreColor = r.Linked.Count > 0 ? RelocationBrush : foreColor;
bool single = r.Linked.Count > 0 && r.Branched.Count == 0
|| (r.Branched.Count > 0 && r.Linked.Count == 0);

bool branch = (r._section.HasCode && r.Code is PPCBranch && _sectionEditor.highlightBlr.Checked);
bool cmd = r.Command != null && ((r.Command.IsHalf && remainder > 1) || (!r.Command.IsHalf));
foreColor = r.Linked.Count > 0 ? RelocationBrush :
r.Branched.Count > 0 ? new SolidBrush(Color.Blue) :
foreColor;

This comment has been minimized.

Copy link
@Sammi-Husky

Sammi-Husky Jan 2, 2015

Author Collaborator

Currently, if there is a location that is both branched to AND linked to via Relocation, this will paint the string as red. The listbox however, will still paint the items correctly whether they are linked branches or linked commands.

if (_sectionEditor._section.HasCode)
{
//Get the currently selected branch code.
//This is not the byte that is being painted!
PPCBranch branchOp = _sectionEditor.TargetBranch;
if (branchOp != null)
{
int index =
!branchOp.Absolute ?
(_sectionEditor.TargetRelocation._index * 4 + branchOp.DataOffset).RoundDown(4) / 4 :
-1; //Absolute from start of section, start of file, or start of memory?

if (index == r._index)
{
backColor = BranchOffsetBrush;
return;
}
}
}
bool blr = (r._section.HasCode && r.Code is PPCblr && _sectionEditor.highlightBlr.Checked);
bool branch = (r._section.HasCode && r.Code is PPCBranch && !(blr || r.Code is PPCbctr));
bool cmd = r.Command != null && ((r.Command.IsHalf && remainder > 1) || (!r.Command.IsHalf));

backColor =
r._selected ? SelectedBrush : //1st: is this selected?
cmd ? CommandBrush : //2nd: is this a command?
branch ? BranchBrush : //3rd: is this a branch?
null; //4th: this is nothing important.
blr ? BlrBrush : //3rd: is this a blr?
branch ? BranchOffsetBrush : //4th: Is this a branch?
null; //5th: this is nothing important.
}

void PaintByte(byte b, long offset, bool isSelectedByte, bool isKeyInterpreterActive, Graphics g, Brush foreBrush, Point gridPoint)
Expand Down Expand Up @@ -3648,21 +3635,21 @@ public Brush CommandBrush
/// Gets or sets the color for code branch relocations.
/// </summary>
[Category("Hex"), Description("Gets or sets the color for code branch relocations.")]
public Color BranchColor
public Color BlrColor
{
get { return _branchColor; }
set { _branchColor = value; Invalidate(); }
} Color _branchColor = Color.FromArgb(255, 255, 100);
get { return _blrColor; }
set { _blrColor = value; Invalidate(); }
} Color _blrColor = Color.FromArgb(255, 255, 100);
[Browsable(false)]
public Brush BranchBrush
public Brush BlrBrush
{
get
{
return _branchBrush ??
(_branchBrush = new SolidBrush(_branchColor));
return _blrBrush ??
(_blrBrush = new SolidBrush(_blrColor));
}
}
Brush _branchBrush = null;
Brush _blrBrush = null;

/// <summary>
/// Gets or sets the color for relocations that are branched to.
Expand All @@ -3672,7 +3659,8 @@ public Color BranchOffsetColor
{
get { return _branchOffsetColor; }
set { _branchOffsetColor = value; Invalidate(); }
} Color _branchOffsetColor = Color.MediumPurple;
} Color _branchOffsetColor = Color.Plum;

[Browsable(false)]
public Brush BranchOffsetBrush
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion BrawlLib/System/Windows/Forms/Section Editor/SectionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ public Relocation TargetRelocation
{
_targetRelocation._selected = true;

lstLinked.DataSource = _targetRelocation.Linked;
lstLinked.Items.Clear();
lstLinked.Items.AddRange(_targetRelocation.Linked.ToArray());
lstLinked.Items.AddRange(_targetRelocation.Branched.ToArray());



if (_section.HasCode && ppcDisassembler1.Visible)
{
Expand Down Expand Up @@ -355,6 +359,7 @@ public Relocation TargetRelocation
_targetRelocation.Code is PPCBranch &&
!(_targetRelocation.Code is PPCblr || _targetRelocation.Code is PPCbctr))
{

_targetBranch = (PPCBranch)_targetRelocation.Code;
btnGotoBranch.Visible = btnGotoBranch.Enabled = (_targetBranchOffsetRelocation = GetBranchOffsetRelocation()) != null;
}
Expand Down Expand Up @@ -711,6 +716,21 @@ private void lstLinked_DoubleClick(object sender, EventArgs e)
if (lstLinked.SelectedItem != null)
OpenRelocation(lstLinked.SelectedItem as Relocation);
}
private void lstLinked_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();

Relocation r = lstLinked.Items[e.Index] as Relocation;

if (r != null)
{
Color c = r.Code is PPCBranch ? Color.DarkBlue :
r.Target != null ? Color.DarkGreen : Color.Black;

e.Graphics.DrawString(r.ToString(), lstLinked.Font, new SolidBrush(c), e.Bounds);
}
e.DrawFocusRectangle();
}

bool _updating = false;
private void txtFloat_TextChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 6082230

Please sign in to comment.