Skip to content

Commit

Permalink
Display offsets 0.2.10 (#4)
Browse files Browse the repository at this point in the history
* bump versions
* Fix display offsets and scaling (virtual 1280x960 screen)

* Fix following and resize
  • Loading branch information
inorton authored Oct 29, 2017
1 parent 71076ba commit 0fbd2f6
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 19 deletions.
2 changes: 0 additions & 2 deletions EDMCOverlay/EDMCOverlay/EDGlassForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public EDGlassForm(System.Diagnostics.Process follow)
this.AutoScaleMode = AutoScaleMode.None;
this.ClientSize = new Size(100, 100);
this.DoubleBuffered = true;
this.Width = 1280;
this.Height = 960;

this.Name = "EDMC Overlay Window";
this.Text = this.Name;
Expand Down
44 changes: 41 additions & 3 deletions EDMCOverlay/EDMCOverlay/EDMCOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,42 @@ private static void TestThread(Object obj)
rect.Fill = "#660000ff";
rect.Id = "rectangle";

Graphic bounds = new Graphic();
bounds.Shape = "vect";
bounds.Color = "#aaff00";
bounds.Id = "bounds";
bounds.TTL = 10;
bounds.Vector = new VectorPoint[] {
new VectorPoint() {
Color = "#00ff00",
Text = "NE",
Marker = "cross",
X = 1280,
Y = 0,
},
new VectorPoint() {
Color = "#00ff00",
Text = "SE",
Marker = "cross",
X = 1280,
Y = 960,
},
new VectorPoint() {
Color = "#00ff00",
Text = "SW",
Marker = "cross",
X = 0,
Y = 960,
},
new VectorPoint() {
Color = "#00ff00",
Text = "NW",
Marker = "cross",
X = 0,
Y = 0,
},
};

Graphic vectorline = new Graphic();
vectorline.Shape = "vect";
vectorline.Color = "#cdcd00";
Expand Down Expand Up @@ -72,7 +108,7 @@ private static void TestThread(Object obj)
test.X = 2*i % 100;
test.Y = i % 100;
test.Color = "red";

server.SendGraphic(bounds, 1);
server.SendGraphic(test, 1);
server.SendGraphic(rect, 1);
server.SendGraphic(vectorline, 1);
Expand All @@ -87,6 +123,7 @@ public static void Main(string[] argv)
Logger.LogMessage(String.Format("unhandled exception!!: {0} {1}", sender, args));
Environment.Exit(1);
};

String appdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
String edmc = System.IO.Path.Combine(appdata, "EDMarketConnector");
String plugins = System.IO.Path.Combine(edmc, "plugins");
Expand All @@ -96,15 +133,16 @@ public static void Main(string[] argv)
Logger.Subsystem = typeof(EDMCOverlay);
try
{
OverlayRenderer renderer = new OverlayRenderer();
if (argv.Length > 0)
{
if (argv[0].Equals("--test"))
{
renderer.TestMode = true;
System.Threading.ThreadPool.QueueUserWorkItem(TestThread);
}
}

OverlayRenderer renderer = new OverlayRenderer();

server = new OverlayJsonServer(5010, renderer);

System.Threading.ThreadPool.QueueUserWorkItem((x) => server.Start());
Expand Down
1 change: 1 addition & 0 deletions EDMCOverlay/EDMCOverlay/EDMCOverlay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<Compile Include="Logger.cs" />
<Compile Include="OverlayJsonServer.cs" />
<Compile Include="OverlayRenderer.cs" />
<Compile Include="Rect.cs" />
<Compile Include="VectorPoint.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down
6 changes: 6 additions & 0 deletions EDMCOverlay/EDMCOverlay/Graphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Graphic
// divide the screen by 12 cols
public int X { get; set; }

// anchor the graphic to an edge of the screen, N E S W NE NW SE SW
public string Anchor { get; set; }

// seconds to display, if zero this will default to a 10 second life,
// any negative number will display the message forever (or until the client quits)
public int TTL { get; set; }
Expand All @@ -40,5 +43,8 @@ public class Graphic

// Vector
public VectorPoint[] Vector { get; set; }

public int OldX { get; set; }
public int OldY { get; set; }
}
}
23 changes: 23 additions & 0 deletions EDMCOverlay/EDMCOverlay/InternalGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public void Update(Graphic g)
expires = DateTime.Now.AddSeconds(g.TTL);
RealGraphic.Text = g.Text;
RealGraphic.Color = g.Color;
RealGraphic.OldX = RealGraphic.X;
RealGraphic.OldY = RealGraphic.Y;
RealGraphic.X = g.X;
RealGraphic.Y = g.Y;
}
Expand All @@ -32,5 +34,26 @@ public bool Expired
return !(lifeleft > 0);
}
}

public Rect InvalidateRect
{
get
{
var r = new Rect();
r.X = RealGraphic.X - 3;
r.Y = RealGraphic.Y - 3;

r.W = RealGraphic.W;
r.H = RealGraphic.H;

if (!String.IsNullOrWhiteSpace(RealGraphic.Text))
{
r.H = 32;
r.W = 24 * RealGraphic.Text.Length;
}

return r;
}
}
}
}
68 changes: 56 additions & 12 deletions EDMCOverlay/EDMCOverlay/OverlayRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public class OverlayRenderer
public const string EDProgramName = "EliteDangerous64";
public const int FPS = 20;

public const int VIRTUAL_WIDTH = 1280;
public const int VIRTUAL_HEIGHT = 960;
public bool TestMode { get; set; }

public const int VIRTUAL_ORIGIN_X = 20;
public const int VIRTUAL_ORIGIN_Y = 40;
public const int VIRTUAL_WIDTH = 1350;
public const int VIRTUAL_HEIGHT = 1060;

Logger Logger = Logger.GetInstance(typeof(OverlayRenderer));

Expand Down Expand Up @@ -163,6 +167,8 @@ private void Clear(Graphics draw)
Glass.Invoke(new Action(() => { Clear(draw); }));
return;
}

// this causes flickering
draw.Clear(Color.Black);
}

Expand All @@ -179,11 +185,29 @@ private void Draw(Graphics draw)
foreach (var id in Graphics.Keys.ToArray())
{
var gfx = Graphics[id];
// clear everything one at a time
var clear = new Graphic();
var inval = gfx.InvalidateRect;
/*
clear.Color = "#000000";
clear.Fill = clear.Color;
clear.Shape = "rect";
clear.H = inval.H;
clear.W = inval.W;
clear.X = inval.X;
clear.Y = inval.Y;
DrawShape(draw, clear);
// did it move?
clear.X = gfx.RealGraphic.OldX;
clear.Y = gfx.RealGraphic.OldY;
DrawShape(draw, clear);
if (gfx.Expired)
{
Graphics.Remove(id);
continue;
}
*/

Graphic g = gfx.RealGraphic;

Expand All @@ -202,8 +226,23 @@ private void Draw(Graphics draw)

}



void allocateBuffers(BufferedGraphicsContext bufctx)
{

}

void swapBuffers(BufferedGraphicsContext bufctx)
{

}

private void StartUpdate()
{
var bufg = BufferedGraphicsManager.Current;
allocateBuffers(bufg);

DateTime lastframe = DateTime.Now;
Graphics draw = null;
Logger.LogMessage("Starting update loop");
Expand Down Expand Up @@ -231,7 +270,7 @@ private void StartUpdate()

if (draw == null)
{
draw = Glass.CreateGraphics();
draw = Glass.CreateGraphics();
draw.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
}

Expand All @@ -242,7 +281,7 @@ private void StartUpdate()
}
IntPtr activeWindow = GetForegroundWindow();

bool foreground = activeWindow == Glass.Follow.MainWindowHandle;
bool foreground = (activeWindow == Glass.Follow.MainWindowHandle) || TestMode;

// if there is nothing to draw, do a big sleep
if (Graphics.Values.Count == 0 || !foreground)
Expand All @@ -268,11 +307,11 @@ Point Scale(int x, int y)
{
Point p = new Point();

double x_factor = (double)(VIRTUAL_WIDTH) / this.Glass.ClientSize.Width;
double y_factor = (double)(VIRTUAL_HEIGHT) / this.Glass.ClientSize.Height;
double x_factor = this.Glass.ClientSize.Width / (double)(VIRTUAL_WIDTH);
double y_factor = this.Glass.ClientSize.Height / (double)(VIRTUAL_HEIGHT);

p.X = (int)Math.Round(x * x_factor);
p.Y = (int)Math.Round(y * y_factor);
p.X = VIRTUAL_ORIGIN_X + (int)Math.Round(x * x_factor);
p.Y = VIRTUAL_ORIGIN_Y + (int)Math.Round(y * y_factor);

return p;
}
Expand Down Expand Up @@ -303,7 +342,7 @@ private void DrawVectorLine(Graphics draw, Brush brush, VectorPoint start, Vecto
draw.DrawLine(p, Scale(start.X, start.Y), Scale(end.X, end.Y));
}

private void DrawVector(Graphics draw, Graphic start)
private void DrawVector(Graphics draw, Graphic start, bool erase)
{
// draw first point
if (start.Vector == null) return;
Expand All @@ -315,15 +354,19 @@ private void DrawVector(Graphics draw, Graphic start)
{
var current = start.Vector[i];
DrawVectorLine(draw, GetBrush(start.Color), last, current);
DrawMarker(draw, last);
DrawMarker(draw, last);
DrawTextEx(draw, GraphicType.FONT_NORMAL, last.Color, last.Text, last.X + 2, last.Y + 7);
last = current;
}

// draw last marker
DrawMarker(draw, last);
DrawTextEx(draw, GraphicType.FONT_NORMAL, last.Color, last.Text, last.X + 2, last.Y + 7);
}

private void DrawVector(Graphics draw, Graphic start)
{
DrawVector(draw, start, false);
}

private void DrawShape(Graphics draw, Graphic g)
Expand Down Expand Up @@ -356,21 +399,22 @@ private void DrawShape(Graphics draw, Graphic g)

private void DrawText(Graphics draw, Graphic g)
{

DrawTextEx(draw, g.Size, g.Color, g.Text, g.X, g.Y);
}

private void DrawTextEx(Graphics draw, String fontsize, String fontcolor, String text, int x, int y)
{
if (String.IsNullOrWhiteSpace(text)) return;

Point loc = Scale(x, y);
Font size = normalFont;
if (fontsize != null)
fontSizes.TryGetValue(fontsize, out size);
Brush paint = GetBrush(fontcolor);

if (paint != null)
{
Point loc = Scale(x, y);
draw.DrawString(text, size, paint, (float)loc.X, (float)loc.Y);
}
}
Expand Down
4 changes: 2 additions & 2 deletions EDMCOverlay/EDMCOverlay/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.0.2.9")]
[assembly: AssemblyFileVersion("0.0.2.9")]
[assembly: AssemblyVersion("0.0.2.10")]
[assembly: AssemblyFileVersion("0.0.2.10")]

0 comments on commit 0fbd2f6

Please sign in to comment.