summaryrefslogtreecommitdiff
path: root/MainForm.cs
blob: 7eae71ee2befbe737223243a508dcf643581ecd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// GfxView - Simple GFX viewer
// Copyright (C) 2005  Ian Cowburn
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// 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.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// $Id$
//
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace GfxView
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox m_gfx;
		private int m_height;
		private double m_size;
		private string m_file;
		
		public MainForm(string file)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		
			m_file=file;
			m_gfx.Image=Bitmap.FromFile(file);
			
			m_height=m_gfx.Image.Height;
			
			m_size=1.0;
			
			while(m_size>0.1 && (Screen.PrimaryScreen.WorkingArea.Height < (m_height*m_size)))
			{
				m_size-=0.01;
			}
			
			SetSize();
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			string file=null;
			
			if (args.Length>0)
			{
				file=args[0];
			}
			else
			{
				OpenFileDialog fsel=new OpenFileDialog();
				
				if (fsel.ShowDialog()==DialogResult.OK)
				{
					file=fsel.FileName;
				}
			}

			if (file!=null)
			{
				try
				{
					Application.Run(new MainForm(file));
				}
				catch (Exception e)
				{
					MessageBox.Show(e.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
			}
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.m_gfx = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// m_gfx
			// 
			this.m_gfx.Dock = System.Windows.Forms.DockStyle.Fill;
			this.m_gfx.Location = new System.Drawing.Point(0, 0);
			this.m_gfx.Name = "m_gfx";
			this.m_gfx.Size = new System.Drawing.Size(292, 266);
			this.m_gfx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.m_gfx.TabIndex = 0;
			this.m_gfx.TabStop = false;
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.m_gfx);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "MainForm";
			this.Text = "MainForm";
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKey);
			this.ResumeLayout(false);
		}
		#endregion
		
		private void SetSize()
		{
			Width=(int)(m_gfx.Image.Width*m_size);
			Height=(int)(m_gfx.Image.Height*m_size);
			
			Text=m_file + " [" + (m_size*100).ToString() + "%]";
		}

		void OnKey(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			switch(Char.ToLower(e.KeyChar))
			{
				case 'q':
					Close();
					break;
					
				case '+':
					m_size+=0.1;
					SetSize();
					break;
					
				case '-':
					m_size=Math.Max(0.01,m_size-0.1);
					SetSize();
					break;

				default:
					break;
			}
		}
		
	}
}