144 lines
4.9 KiB
C#
144 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
|
|
namespace Ubi.Tools.GearConfigTool
|
|
{
|
|
enum TreeviewStyles
|
|
{
|
|
Opened = 0,
|
|
Closed = 1
|
|
}
|
|
|
|
public enum CheckboxStyles
|
|
{
|
|
NotChecked = 0,
|
|
Checked = 1,
|
|
Squared = 2,
|
|
|
|
NotCheckedShaded = 3,
|
|
CheckedShaded = 4,
|
|
SquaredShaded = 5
|
|
}
|
|
|
|
/**
|
|
* Class used to generate ImageList used by the GEARDataGridView object.
|
|
*
|
|
* GenerateTreeviewStyle Generate 2 differents image a + and a - sign enclosed in a box.
|
|
* Used to denote the state of a row in a tree view.
|
|
* TreeviewStyles list all the differents image generated by this method.
|
|
*
|
|
* GenerateCheckboxStyle Generate 6 differents image that denote the dependencies of a Module.
|
|
* CheckboxStyles list all the differents image generated by this method.
|
|
*
|
|
*/
|
|
class UtilsGenerateImage
|
|
{
|
|
private static int IMAGE_WIDTH = 16;
|
|
private static int IMAGE_HEIGHT = 16;
|
|
|
|
public static ImageList GenerateTreeviewStyle()
|
|
{
|
|
// iList will contain all the check box images returned
|
|
ImageList iList = new ImageList();
|
|
Graphics graphics = null;
|
|
|
|
Pen blackPen = new Pen(Color.Black);
|
|
SolidBrush whiteBrush = new SolidBrush(Color.White);
|
|
|
|
int width = 8;
|
|
int height = 8;
|
|
|
|
// Draw the '-' square...
|
|
Bitmap treeItemClosed = new Bitmap(IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
graphics = Graphics.FromImage(treeItemClosed);
|
|
|
|
graphics.FillRectangle(whiteBrush, 0, 0, width, height);
|
|
graphics.DrawRectangle(blackPen, 0, 0, width - 0, height - 0);
|
|
graphics.DrawLine(blackPen, 2, height / 2, width - 2, height / 2);
|
|
|
|
iList.Images.Add(treeItemClosed);
|
|
|
|
// Draw the '+' square...
|
|
Bitmap treeItemOpened = new Bitmap(treeItemClosed);
|
|
graphics = Graphics.FromImage(treeItemOpened);
|
|
|
|
graphics.DrawLine(blackPen, width / 2, 2, width / 2, height - 2);
|
|
|
|
iList.Images.Add(treeItemOpened);
|
|
|
|
return iList;
|
|
}
|
|
|
|
public static ImageList GenerateCheckboxStyle()
|
|
{
|
|
|
|
// iList will contain all the check box images returned
|
|
ImageList iList = new ImageList();
|
|
Graphics graphics = null;
|
|
|
|
// Create a list of pens to generate 2 differents image set.
|
|
// One will be black on white and the other will be dark gray on light gray...
|
|
List<Pen> pens = new List<Pen>();
|
|
|
|
Pen blackPen = new Pen(Color.Black);
|
|
blackPen.Width = 2.0f;
|
|
blackPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
|
|
|
|
Pen darkGrayPen = new Pen(Color.DarkGray);
|
|
darkGrayPen.Width = 2.0f;
|
|
darkGrayPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
|
|
|
|
pens.Add(blackPen);
|
|
pens.Add(darkGrayPen);
|
|
|
|
// Create the list of brush...
|
|
List<List<Brush>> brushes = new List<List<Brush>>();
|
|
|
|
List<Brush> l1 = new List<Brush>();
|
|
l1.Add(new SolidBrush(Color.White));
|
|
l1.Add(new SolidBrush(Color.Black));
|
|
brushes.Add(l1);
|
|
|
|
List<Brush> l2 = new List<Brush>();
|
|
l2.Add(new SolidBrush(Color.LightGray));
|
|
l2.Add(new SolidBrush(Color.DarkGray));
|
|
brushes.Add(l2);
|
|
|
|
// shade == 0 is the normal version
|
|
// shade == 1 is the shaded version
|
|
for (int shade = 0; shade < 2; shade++)
|
|
{
|
|
// The check box not checked...
|
|
Bitmap checkboxNotChecked = new Bitmap(IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
graphics = Graphics.FromImage(checkboxNotChecked);
|
|
|
|
graphics.FillRectangle(brushes[shade][0], 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
graphics.DrawRectangle(pens[shade], 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
|
|
iList.Images.Add(checkboxNotChecked);
|
|
|
|
// The check box checked
|
|
Bitmap checkboxChecked = new Bitmap(checkboxNotChecked);
|
|
graphics = Graphics.FromImage(checkboxChecked);
|
|
|
|
graphics.DrawLine(pens[shade], new Point(4, 8), new Point(8, 12));
|
|
graphics.DrawLine(pens[shade], new Point(8, 12), new Point(12, 4));
|
|
|
|
iList.Images.Add(checkboxChecked);
|
|
|
|
// The check box squared
|
|
Bitmap checkboxSquared = new Bitmap(checkboxNotChecked);
|
|
graphics = Graphics.FromImage(checkboxSquared);
|
|
|
|
graphics.FillRectangle(brushes[shade][1], 3, 3, IMAGE_WIDTH - 6, IMAGE_HEIGHT - 6);
|
|
|
|
iList.Images.Add(checkboxSquared);
|
|
}
|
|
|
|
return iList;
|
|
}
|
|
}
|
|
}
|