Develop and Download Open Source Software

Browse Subversion Repository

Contents of /NeoFT/Controls/HeightBar.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download)
Tue Mar 25 12:06:05 2008 UTC (16 years ago) by c477
File size: 10892 byte(s)


1 using System;
2 using System.Collections;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Diagnostics;
7 using System.IO;
8 using System.Windows.Forms;
9 using System.Resources;
10 using System.Reflection;
11
12 namespace nft.controls
13 {
14 /// <summary>
15 /// HeightBar ‚ĚŠT—v‚Ěŕ–ž‚Ĺ‚ˇB
16 /// </summary>
17 public class HeightBar : System.Windows.Forms.UserControl
18 {
19 private System.Windows.Forms.Button btnUp;
20 private System.Windows.Forms.PictureBox barArea;
21 private System.Windows.Forms.Button btnDown;
22 private System.ComponentModel.IContainer components;
23 private Bitmap bmGauge;
24 private bool loaded = false;
25 static private Bitmap bmGround;
26 private System.Windows.Forms.ImageList imageList;
27 private GripLabel grip;
28 static private Bitmap bmInfinity;
29
30 static HeightBar(){
31 try{
32 // TODO!!!!
33 ResourceManager rm = new ResourceManager("nft.controls.resources",Assembly.GetExecutingAssembly());
34 String [] sa = Assembly.GetExecutingAssembly().GetManifestResourceNames();
35 for(int i =0; i<sa.Length; i++)
36 Debug.WriteLine(sa[i]);
37
38 bmGround = rm.GetObject("Image.Ground") as Bitmap;
39 bmInfinity = rm.GetObject("Image.Infinity") as Bitmap;
40 }catch(Exception e){
41 Debug.WriteLine(e.Message);
42 Debug.WriteLine(e.StackTrace);
43 }
44 }
45
46 public HeightBar()
47 {
48 // ‚ą‚ĚŒÄ‚Ńo‚ľ‚́AWindows.Forms ƒtƒH[ƒ€ ƒfƒUƒCƒi‚Ĺ•K—v‚Ĺ‚ˇB
49 InitializeComponent();
50 grip = new GripLabel();
51 Controls.Add(grip);
52 }
53
54 #region colorProperties
55 private Color clGrid = SystemColors.WindowText;
56 private Color clGridSelect = SystemColors.HighlightText;
57 private Color clFillAbove = SystemColors.Window;
58 private Color clFillGround = SystemColors.Window;
59 private Color clFillUnder = SystemColors.Window;
60 private Color clFillAboveSelect = SystemColors.Highlight;
61 private Color clFillGroundSelect = SystemColors.Highlight;
62 private Color clFillUnderSelect = SystemColors.Highlight;
63
64 public Color GridColor { get { return clGrid; } set { clGrid = value; createGaugeImage(); } }
65 public Color GridSelectedColor { get { return clGridSelect; } set { clGridSelect = value; createGaugeImage(); } }
66 public Color FillAboveGroundColor { get { return clFillAbove; } set { clFillAbove = value; createGaugeImage(); } }
67 public Color FillAboveGroundSelectedColor { get { return clFillAboveSelect; } set { clFillAboveSelect = value; createGaugeImage(); } }
68 public Color FillOnGroundColor { get { return clFillGround; } set { clFillGround = value; createGaugeImage(); } }
69 public Color FillOnGroundSelectedColor { get { return clFillGroundSelect; } set { clFillGroundSelect = value; createGaugeImage(); } }
70 public Color FillUnderGroundColor { get { return clFillUnder; } set { clFillUnder = value; createGaugeImage(); } }
71 public Color FillUnderGroundSelectedColor { get { return clFillUnderSelect; } set { clFillUnderSelect = value; createGaugeImage(); } }
72 #endregion
73
74 private int aboveTicks = 10;
75 private int underTicks = 4;
76 private int tickHeight;
77 private int groundHeight = 0;
78 private int infiniHeight = 0;
79
80 public int TicksAboveGround {
81 get { return aboveTicks; }
82 set{ aboveTicks = Math.Min(100,Math.Max(0,value)); createGaugeImage(); }
83 }
84 public int TicksUnderGround {
85 get { return underTicks; }
86 set{ underTicks = Math.Min(100,Math.Max(0,value)); createGaugeImage(); }
87 }
88
89 protected override void OnLoad(EventArgs e) {
90 base.OnLoad (e);
91 }
92
93
94 protected override void OnSizeChanged(EventArgs e) {
95 base.OnSizeChanged (e);
96 createGaugeImage();
97 }
98
99 protected void createGaugeImage(){
100 if(!loaded && !DesignMode) return;
101 if(bmGauge!=null)
102 bmGauge.Dispose();
103 int barHeight = barArea.Height;
104 int barWidth = barArea.Width;
105 bmGauge = new Bitmap(barWidth,barHeight);
106 int n = TicksAboveGround+TicksUnderGround+2;
107 if(n*2>barHeight){
108 tickHeight = 2;
109 if((TicksUnderGround+2)*2>barHeight){
110 aboveTicks=0;
111 int t = (barHeight>>1)-2;
112 underTicks=t;
113 if(t<0)
114 tickHeight = 0;
115 }else{
116 aboveTicks=(barHeight>>1)-TicksUnderGround-2;
117 }
118 } else {
119 tickHeight = (int)Math.Floor((barHeight-1)/(double)n);
120 }
121 if(tickHeight!=0){
122 int m = barHeight - n*tickHeight;
123 int gh = bmGround.Height;
124 if((m+tickHeight)>gh) {
125 groundHeight = Math.Max(gh,tickHeight);
126 infiniHeight = (tickHeight<<1) + m - groundHeight;
127 }
128 else {
129 groundHeight = tickHeight;
130 infiniHeight = tickHeight+m;
131 }
132 }
133
134 using(Graphics g = Graphics.FromImage(bmGauge)){
135 using( BrushSet bs = new BrushSet(this) ){
136 if(tickHeight==0){
137 g.FillRectangle(SystemBrushes.Control,0,0,barWidth,barHeight);
138 }else {
139 int y = TicksAboveGround*tickHeight+infiniHeight;
140 g.FillRectangle(bs.AboveGround,0,0,barWidth,y);
141 g.FillRectangle(bs.Ground,0,y,barWidth,groundHeight);
142 y += groundHeight;
143 g.FillRectangle(bs.UnderGround,0,y,barWidth,barHeight-y);
144
145 barWidth--;
146 g.DrawRectangle(bs.Grid,0,-1,barWidth,infiniHeight);
147 int h = infiniHeight-1;
148 for(int i=0; i<TicksAboveGround; i++){
149 g.DrawRectangle(bs.Grid,0,h,barWidth,tickHeight);
150 h+=tickHeight;
151 }
152 g.DrawRectangle(bs.Grid,0,h,barWidth,groundHeight);
153 h+=groundHeight;
154 for(int i=0; i<TicksUnderGround; i++){
155 g.DrawRectangle(bs.Grid,0,h,barWidth,tickHeight);
156 h+=tickHeight;
157 }
158 }
159 }
160 }
161 barArea.Image = bmGauge;
162 }
163
164 /// <summary>
165 /// Žg—p‚ł‚ę‚Ä‚˘‚郊ƒ\[ƒX‚ÉŒăˆ—‚đŽŔs‚ľ‚Ü‚ˇB
166 /// </summary>
167 protected override void Dispose( bool disposing )
168 {
169 if( disposing ) {
170 if(components != null) {
171 components.Dispose();
172 }
173 }
174 base.Dispose( disposing );
175 }
176
177 protected override void OnVisibleChanged(EventArgs e) {
178 base.OnVisibleChanged (e);
179 if(!loaded){
180 loaded = true;
181 createGaugeImage();
182 }
183 }
184
185
186 #region ƒRƒ“ƒ|[ƒlƒ“ƒg ƒfƒUƒCƒi‚ŐśŹ‚ł‚ę‚˝ƒR[ƒh
187 /// <summary>
188 /// ƒfƒUƒCƒi ƒTƒ|[ƒg‚É•K—v‚Čƒƒ\ƒbƒh‚Ĺ‚ˇB‚ą‚Ěƒƒ\ƒbƒh‚Ě“ŕ—e‚đ
189 /// ƒR[ƒh ƒGƒfƒBƒ^‚Ĺ•ĎX‚ľ‚Č‚˘‚Ĺ‚­‚ž‚ł‚˘B
190 /// </summary>
191 private void InitializeComponent()
192 {
193 this.components = new System.ComponentModel.Container();
194 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HeightBar));
195 this.btnUp = new System.Windows.Forms.Button();
196 this.imageList = new System.Windows.Forms.ImageList(this.components);
197 this.btnDown = new System.Windows.Forms.Button();
198 this.barArea = new System.Windows.Forms.PictureBox();
199 this.SuspendLayout();
200 //
201 // btnUp
202 //
203 this.btnUp.Dock = System.Windows.Forms.DockStyle.Top;
204 this.btnUp.Font = new System.Drawing.Font("‚l‚r ‚oƒSƒVƒbƒN", 5.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
205 this.btnUp.ImageIndex = 0;
206 this.btnUp.ImageList = this.imageList;
207 this.btnUp.Location = new System.Drawing.Point(0, 0);
208 this.btnUp.Name = "btnUp";
209 this.btnUp.Size = new System.Drawing.Size(13, 13);
210 this.btnUp.TabIndex = 1;
211 //
212 // imageList
213 //
214 this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth4Bit;
215 this.imageList.ImageSize = new System.Drawing.Size(7, 6);
216 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
217 this.imageList.TransparentColor = System.Drawing.Color.White;
218 //
219 // btnDown
220 //
221 this.btnDown.Dock = System.Windows.Forms.DockStyle.Bottom;
222 this.btnDown.Font = new System.Drawing.Font("‚l‚r ‚oƒSƒVƒbƒN", 5.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
223 this.btnDown.ImageIndex = 1;
224 this.btnDown.ImageList = this.imageList;
225 this.btnDown.Location = new System.Drawing.Point(0, 137);
226 this.btnDown.Name = "btnDown";
227 this.btnDown.Size = new System.Drawing.Size(13, 13);
228 this.btnDown.TabIndex = 1;
229 //
230 // barArea
231 //
232 this.barArea.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
233 | System.Windows.Forms.AnchorStyles.Left)
234 | System.Windows.Forms.AnchorStyles.Right)));
235 this.barArea.Location = new System.Drawing.Point(0, 13);
236 this.barArea.Name = "barArea";
237 this.barArea.Size = new System.Drawing.Size(13, 124);
238 this.barArea.TabIndex = 2;
239 this.barArea.TabStop = false;
240 //
241 // HeightBar
242 //
243 this.Controls.Add(this.btnUp);
244 this.Controls.Add(this.btnDown);
245 this.Controls.Add(this.barArea);
246 this.Name = "HeightBar";
247 this.Size = new System.Drawing.Size(13, 150);
248 this.ResumeLayout(false);
249
250 }
251 #endregion
252 }
253
254 class GripLabel : Label {
255 private Color border;
256
257 public Color BorderColor { get { return border; } set { border = value; Invalidate(); } }
258 protected override void OnPaint(PaintEventArgs e) {
259 base.OnPaint (e);
260 using(Pen p = new Pen(border)){
261 e.Graphics.DrawRectangle(p,0,0,Width-1,Height-1);
262 }
263 }
264
265 }
266
267 class BrushSet : IDisposable {
268 #region
269 enum BrushIndex { above, ground, under, aboveSel, groundSel, underSel };
270 Brush[] brushes;
271 Pen normal,selected;
272
273 public BrushSet(HeightBar owner){
274 brushes = new Brush[6];
275 normal = new Pen(owner.GridColor);
276 selected =new Pen(owner.GridSelectedColor);
277 brushes[(int)BrushIndex.above] =new SolidBrush(owner.FillAboveGroundColor);
278 brushes[(int)BrushIndex.ground] =new SolidBrush(owner.FillOnGroundColor);
279 brushes[(int)BrushIndex.under] =new SolidBrush(owner.FillUnderGroundColor);
280 brushes[(int)BrushIndex.aboveSel] =new SolidBrush(owner.FillAboveGroundSelectedColor);
281 brushes[(int)BrushIndex.groundSel] =new SolidBrush(owner.FillOnGroundSelectedColor);
282 brushes[(int)BrushIndex.underSel] =new SolidBrush(owner.FillUnderGroundSelectedColor);
283 }
284
285 public Pen Grid { get { return normal; }}
286 public Pen GridSelected { get { return selected; }}
287 public Brush AboveGround { get { return brushes[(int)BrushIndex.above]; }}
288 public Brush AboveSelected { get { return brushes[(int)BrushIndex.aboveSel]; }}
289 public Brush Ground { get { return brushes[(int)BrushIndex.ground]; }}
290 public Brush GroundSelected { get { return brushes[(int)BrushIndex.groundSel]; }}
291 public Brush UnderGround { get { return brushes[(int)BrushIndex.under]; }}
292 public Brush UnderSelected { get { return brushes[(int)BrushIndex.underSel]; }}
293
294 public void Dispose() {
295 normal.Dispose();
296 selected.Dispose();
297 normal = null;
298 selected = null;
299 for(int i=0; i<brushes.Length; i++ ) {
300 brushes[i].Dispose();
301 }
302 brushes = null;
303 }
304 #endregion
305 }
306 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26