Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions STROOP/Controls/VariablePanel/VariablePanel.Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ protected override void OnPaint(PaintEventArgs e)
bufferedGraphics.Render(e.Graphics);
}

public static Brush ForegroundBrushForBackground(Color background)
{
int yiq = ((background.R * 299) + (background.G * 587) + (background.B * 114)) / 1000;
return yiq >= 128 ? Brushes.Black : Brushes.White;
}

public void Draw()
{
//Return if not focused and recently enough refreshed to save CPU
Expand Down Expand Up @@ -335,7 +341,8 @@ void GetColumn(int offset, int width, bool clip = true)
else
ctrlData.nameTextOffset = 0;

g.DrawString(cell.control.VarName, varNameFont, cell.control.IsSelected ? Brushes.White : Brushes.Black, txtPoint);
var backgroundColor = cell.control.IsSelected ? Color.Blue : cell.control.currentColor;
g.DrawString(cell.control.VarName, varNameFont, ForegroundBrushForBackground(backgroundColor), txtPoint);
}

ResetIterators();
Expand Down Expand Up @@ -363,7 +370,8 @@ void GetColumn(int offset, int width, bool clip = true)
else
{
var txtPoint = new Point((x + 1) * elementWidth - elementMarginLeftRight, yCoord + elementMarginTopBottom);
g.DrawString(cell.GetValueText(), Font, cell.control.IsSelected ? Brushes.White : Brushes.Black, txtPoint, rightAlignFormat);
var backgroundColor = cell.control.IsSelected ? Color.Blue : cell.control.currentColor;
g.DrawString(cell.GetValueText(), Font, ForegroundBrushForBackground(backgroundColor), txtPoint, rightAlignFormat);
}

DrawFixImage(cell, x * elementWidth + elementNameWidth, yCoord);
Expand Down Expand Up @@ -448,7 +456,10 @@ void DrawMovingVariables()
elementNameWidth,
elementHeight));
var txtPoint = new Point((int)ctrlData.positionWhileMoving.X + elementMarginLeftRight, yCoord + elementMarginTopBottom);
g.DrawString(cell.control.VarName, varNameFont, Brushes.Black, txtPoint);

var backgroundColor = cell.control.currentColor;
var foregroundBrush = ForegroundBrushForBackground(backgroundColor);
g.DrawString(cell.control.VarName, varNameFont, foregroundBrush, txtPoint);

var valueX = (int)ctrlData.positionWhileMoving.X + elementNameWidth;
g.Clip = new Region(
Expand All @@ -458,7 +469,7 @@ void DrawMovingVariables()
elementValueWidth,
elementHeight));
txtPoint = new Point((int)ctrlData.positionWhileMoving.X + elementWidth - elementMarginLeftRight, yCoord + elementMarginTopBottom);
g.DrawString(cell.GetValueText(), Font, Brushes.Black, txtPoint, rightAlignFormat);
g.DrawString(cell.GetValueText(), Font, foregroundBrush, txtPoint, rightAlignFormat);
DrawFixImage(cell, valueX, yCoord);

g.ResetClip();
Expand Down
3 changes: 2 additions & 1 deletion STROOP/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using STROOP.Core;
using STROOP.Core;
using STROOP.Forms;
using System;
using System.Drawing;
Expand Down Expand Up @@ -38,6 +38,7 @@

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetColorMode(SystemColorMode.System);

Check failure on line 41 in STROOP/Program.cs

View workflow job for this annotation

GitHub Actions / debug-build

'Application' does not contain a definition for 'SetColorMode'

Check failure on line 41 in STROOP/Program.cs

View workflow job for this annotation

GitHub Actions / debug-build

The name 'SystemColorMode' does not exist in the current context

Check failure on line 41 in STROOP/Program.cs

View workflow job for this annotation

GitHub Actions / debug-build

'Application' does not contain a definition for 'SetColorMode'

Check failure on line 41 in STROOP/Program.cs

View workflow job for this annotation

GitHub Actions / debug-build

The name 'SystemColorMode' does not exist in the current context

StroopMainForm mainForm;
Initialize(out mainForm);
Expand Down
Loading