2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Drawing;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
2007-10-21 12:58:56 +00:00
|
|
|
using SlimDX.Direct3D;
|
2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
|
|
|
internal sealed class ColorCollection
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2007-10-21 13:51:08 +00:00
|
|
|
// Assist color creation
|
2007-10-21 12:58:56 +00:00
|
|
|
private const float BRIGHT_MULTIPLIER = 1.0f;
|
|
|
|
private const float BRIGHT_ADDITION = 0.4f;
|
|
|
|
private const float DARK_MULTIPLIER = 0.9f;
|
|
|
|
private const float DARK_ADDITION = -0.2f;
|
|
|
|
|
2007-10-21 13:51:08 +00:00
|
|
|
// Palette size
|
|
|
|
private const int NUM_COLORS = 20;
|
|
|
|
|
|
|
|
// Colors!
|
|
|
|
public const int BACKGROUND = 0;
|
|
|
|
public const int VERTICES = 1;
|
|
|
|
public const int LINEDEFS = 2;
|
|
|
|
public const int ACTIONS = 3;
|
|
|
|
public const int SOUNDS = 4;
|
|
|
|
public const int HIGHLIGHT = 5;
|
|
|
|
public const int SELECTION = 6;
|
|
|
|
public const int ASSOCIATION = 7;
|
|
|
|
public const int GRID = 8;
|
|
|
|
public const int GRID64 = 9;
|
|
|
|
public const int CROSSHAIR3D = 10;
|
|
|
|
public const int HIGHLIGHT3D = 11;
|
|
|
|
public const int SELECTION3D = 12;
|
|
|
|
public const int SCRIPTBACKGROUND = 13;
|
|
|
|
public const int LINENUMBERS = 14;
|
|
|
|
public const int PLAINTEXT = 15;
|
|
|
|
public const int COMMENTS = 16;
|
|
|
|
public const int KEYWORDS = 17;
|
|
|
|
public const int LITERALS = 18;
|
|
|
|
public const int CONSTANTS = 19;
|
|
|
|
|
2007-10-20 01:04:47 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Colors
|
2007-10-21 13:51:08 +00:00
|
|
|
private PixelColor[] colors;
|
|
|
|
private PixelColor[] brightcolors;
|
|
|
|
private PixelColor[] darkcolors;
|
2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-10-21 13:51:08 +00:00
|
|
|
public PixelColor[] Colors { get { return colors; } }
|
|
|
|
public PixelColor[] BrightColors { get { return brightcolors; } }
|
|
|
|
public PixelColor[] DarkColors { get { return darkcolors; } }
|
2007-10-20 10:02:20 +00:00
|
|
|
|
2007-10-21 13:51:08 +00:00
|
|
|
public PixelColor Background { get { return colors[BACKGROUND]; } set { colors[BACKGROUND] = value; } }
|
|
|
|
public PixelColor Vertices { get { return colors[VERTICES]; } set { colors[VERTICES] = value; } }
|
|
|
|
public PixelColor Linedefs { get { return colors[LINEDEFS]; } set { colors[LINEDEFS] = value; } }
|
|
|
|
public PixelColor Actions { get { return colors[ACTIONS]; } set { colors[ACTIONS] = value; } }
|
|
|
|
public PixelColor Sounds { get { return colors[SOUNDS]; } set { colors[SOUNDS] = value; } }
|
|
|
|
public PixelColor Highlight { get { return colors[HIGHLIGHT]; } set { colors[HIGHLIGHT] = value; } }
|
|
|
|
public PixelColor Selection { get { return colors[SELECTION]; } set { colors[SELECTION] = value; } }
|
|
|
|
public PixelColor Association { get { return colors[ASSOCIATION]; } set { colors[ASSOCIATION] = value; } }
|
|
|
|
public PixelColor Grid { get { return colors[GRID]; } set { colors[GRID] = value; } }
|
|
|
|
public PixelColor Grid64 { get { return colors[GRID64]; } set { colors[GRID64] = value; } }
|
|
|
|
|
|
|
|
public PixelColor Crosshair3D { get { return colors[CROSSHAIR3D]; } set { colors[CROSSHAIR3D] = value; } }
|
|
|
|
public PixelColor Highlight3D { get { return colors[HIGHLIGHT3D]; } set { colors[HIGHLIGHT3D] = value; } }
|
|
|
|
public PixelColor Selection3D { get { return colors[SELECTION3D]; } set { colors[SELECTION3D] = value; } }
|
|
|
|
|
|
|
|
public PixelColor ScriptBackground { get { return colors[SCRIPTBACKGROUND]; } set { colors[SCRIPTBACKGROUND] = value; } }
|
|
|
|
public PixelColor LineNumbers { get { return colors[LINENUMBERS]; } set { colors[LINENUMBERS] = value; } }
|
|
|
|
public PixelColor PlainText { get { return colors[PLAINTEXT]; } set { colors[PLAINTEXT] = value; } }
|
|
|
|
public PixelColor Comments { get { return colors[COMMENTS]; } set { colors[COMMENTS] = value; } }
|
|
|
|
public PixelColor Keywords { get { return colors[KEYWORDS]; } set { colors[KEYWORDS] = value; } }
|
|
|
|
public PixelColor Literals { get { return colors[LITERALS]; } set { colors[LITERALS] = value; } }
|
|
|
|
public PixelColor Constants { get { return colors[CONSTANTS]; } set { colors[CONSTANTS] = value; } }
|
2007-10-20 01:04:47 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor for settings from configuration
|
|
|
|
public ColorCollection(Configuration cfg)
|
|
|
|
{
|
|
|
|
// Initialize
|
2007-10-21 13:51:08 +00:00
|
|
|
colors = new PixelColor[NUM_COLORS];
|
|
|
|
brightcolors = new PixelColor[NUM_COLORS];
|
|
|
|
darkcolors = new PixelColor[NUM_COLORS];
|
2007-10-21 12:58:56 +00:00
|
|
|
|
2007-10-20 01:04:47 +00:00
|
|
|
// Read all colors from config
|
2007-10-21 13:51:08 +00:00
|
|
|
for(int i = 0; i < NUM_COLORS; i++)
|
2007-10-20 01:04:47 +00:00
|
|
|
{
|
2007-10-21 13:51:08 +00:00
|
|
|
// Read color
|
|
|
|
colors[i] = PixelColor.FromInt(cfg.ReadSetting("colors.color" + i.ToString(CultureInfo.InvariantCulture), -1));
|
2007-10-20 01:04:47 +00:00
|
|
|
}
|
2007-10-21 13:51:08 +00:00
|
|
|
|
2007-10-21 12:58:56 +00:00
|
|
|
// Create assist colors
|
|
|
|
CreateAssistColors();
|
|
|
|
|
2007-10-20 01:04:47 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy constructor
|
|
|
|
public ColorCollection(ColorCollection collection)
|
|
|
|
{
|
|
|
|
// Initialize
|
2007-10-21 13:51:08 +00:00
|
|
|
colors = new PixelColor[NUM_COLORS];
|
|
|
|
brightcolors = new PixelColor[NUM_COLORS];
|
|
|
|
darkcolors = new PixelColor[NUM_COLORS];
|
2007-10-20 01:04:47 +00:00
|
|
|
|
2007-10-21 13:51:08 +00:00
|
|
|
// Copy all colors
|
|
|
|
for(int i = 0; i < NUM_COLORS; i++)
|
|
|
|
colors[i] = collection.colors[i];
|
|
|
|
|
|
|
|
// Create assist colors
|
|
|
|
CreateAssistColors();
|
|
|
|
|
2007-10-20 01:04:47 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2007-10-21 12:58:56 +00:00
|
|
|
// This clamps a value between 0 and 1
|
|
|
|
private float Saturate(float v)
|
|
|
|
{
|
|
|
|
if(v < 0f) return 0f; else if(v > 1f) return 1f; else return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This creates assist colors
|
|
|
|
public void CreateAssistColors()
|
|
|
|
{
|
|
|
|
ColorValue o;
|
|
|
|
ColorValue c = new ColorValue(1f, 0f, 0f, 0f);
|
|
|
|
|
|
|
|
// Go for all colors
|
2007-10-21 13:51:08 +00:00
|
|
|
for(int i = 0; i < NUM_COLORS; i++)
|
2007-10-21 12:58:56 +00:00
|
|
|
{
|
|
|
|
// Get original color
|
2007-10-21 13:51:08 +00:00
|
|
|
o = ColorValue.FromColor(Color.FromArgb(colors[i].ToInt()));
|
2007-10-21 12:58:56 +00:00
|
|
|
|
|
|
|
// Create brighter color
|
|
|
|
c.Red = Saturate(o.Red * BRIGHT_MULTIPLIER + BRIGHT_ADDITION);
|
|
|
|
c.Green = Saturate(o.Green * BRIGHT_MULTIPLIER + BRIGHT_ADDITION);
|
|
|
|
c.Blue = Saturate(o.Blue * BRIGHT_MULTIPLIER + BRIGHT_ADDITION);
|
2007-10-21 13:51:08 +00:00
|
|
|
brightcolors[i] = PixelColor.FromInt(c.ToArgb());
|
2007-10-21 12:58:56 +00:00
|
|
|
|
|
|
|
// Create darker color
|
|
|
|
c.Red = Saturate(o.Red * DARK_MULTIPLIER + DARK_ADDITION);
|
|
|
|
c.Green = Saturate(o.Green * DARK_MULTIPLIER + DARK_ADDITION);
|
|
|
|
c.Blue = Saturate(o.Blue * DARK_MULTIPLIER + DARK_ADDITION);
|
2007-10-21 13:51:08 +00:00
|
|
|
darkcolors[i] = PixelColor.FromInt(c.ToArgb());
|
2007-10-21 12:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-20 01:04:47 +00:00
|
|
|
// This applies colors to this collection
|
|
|
|
public void Apply(ColorCollection collection)
|
|
|
|
{
|
2007-10-21 13:51:08 +00:00
|
|
|
// Copy all colors
|
|
|
|
for(int i = 0; i < NUM_COLORS; i++)
|
|
|
|
colors[i] = collection.colors[i];
|
2007-10-21 12:58:56 +00:00
|
|
|
|
|
|
|
// Rebuild assist colors
|
|
|
|
CreateAssistColors();
|
2007-10-20 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This saves colors to configuration
|
|
|
|
public void SaveColors(Configuration cfg)
|
|
|
|
{
|
2007-10-21 13:51:08 +00:00
|
|
|
// Write all colors to config
|
|
|
|
for(int i = 0; i < NUM_COLORS; i++)
|
2007-10-20 01:04:47 +00:00
|
|
|
{
|
2007-10-21 13:51:08 +00:00
|
|
|
// Write color
|
|
|
|
cfg.WriteSetting("colors.color" + i.ToString(CultureInfo.InvariantCulture), colors[i].ToInt());
|
2007-10-20 01:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|