using FlashDevelop; using PluginCore; using PluginCore.Managers; using ProjectManager.Projects; using System; using System.Windows; using System.Windows.Forms; using System.Drawing; using System.Drawing.Imaging; using System.ComponentModel; /* * 連番のダミー画像を生成するマクロ for FlashDevelop */ namespace Execute { public class CreateDummyImage { // 設定ファイル名(フルパス) public static string FILENAME = "C:/Program Files/FlashDevelop/config"; // ---------------------------------------------------------------- private static int n_w; private static int n_h; private static int n_num; private static int n_st; private static int n_fig; private static string st_top; private static string st_for; public static void Execute() { string[] ar = FILENAME.Split('/'); string d = ar[0]; int i; for (i = 1; i < ar.Length-1; i++) d += '/' + ar[i]; if (! (System.IO.Directory.Exists(d) && System.IO.File.Exists(ar[i])) ) { System.IO.Directory.CreateDirectory(d); createConfigFile(); } else { System.Text.Encoding enc = System.Text.Encoding.GetEncoding(932); string[] lines = System.IO.File.ReadAllLines(FILENAME, enc); try { n_w = int.Parse(lines[0]); n_h = int.Parse(lines[1]); n_num = int.Parse(lines[2]); n_st = int.Parse(lines[3]); n_fig = int.Parse(lines[4]); st_top = lines[5]; st_for = lines[6]; } catch { createConfigFile(); } } showMenuWindow(); } private static void createConfigFile() { n_w = 320; n_h = 240; n_num = 10; n_st = 0; n_fig = 1; st_top = "pic_"; st_for = "png"; string str = "320\n240\n10\n0\n1\npic_\npng"; System.IO.File.WriteAllText(FILENAME, str); } private static void showMenuWindow() { Dialogue d = new Dialogue(); d.Initialize(n_w, n_h, n_num, n_st, st_top, n_fig, st_for); d.ShowDialog(); if (d.save) { n_w = (int)d.nud_w.Value; n_h = (int)d.nud_h.Value; n_num = (int)d.nud_num.Value; n_st = (int)d.nud_st.Value; n_fig = (int)d.nud_fig.Value; st_for = (string)d.cb_for.Text; st_top = (string)d.tb_top.Text; string path = (string)d.path; d.Dispose(); createImages(n_w, n_h, n_num, n_st, st_top, path, n_fig, st_for); // ------------------------------------------------------------ string str = n_w + "\n"+n_h+"\n"+n_num+"\n"+n_st+"\n"+n_fig+"\n"+st_top+"\n"+st_for; System.IO.File.WriteAllText(FILENAME, str); } else { d.Dispose(); } } private static void createImages(int width, int height, int num, int st, string top, string path, int fig, string format) { Bitmap img = new Bitmap(width, height); Graphics g = Graphics.FromImage(img); Font fnt = new Font("MS ゴシック", 10, GraphicsUnit.Pixel); SolidBrush sb = new SolidBrush(Color.FromArgb(255, 200, 50, 100)); Random r = new Random(); string ext = ".png"; ImageFormat ifor = ImageFormat.Png; switch (st_for) { case "png": ext = ".png"; ifor = ImageFormat.Png; break; case "jpg": ext = ".jpg"; ifor = ImageFormat.Jpeg; break; case "gif": ext = ".gif"; ifor = ImageFormat.Gif; break; case "bmp": ext = ".bmp"; ifor = ImageFormat.Bmp; break; } for (int i = 0; i < num; i++) { sb.Color = Color.FromArgb(255, r.Next(25,225), r.Next(25,225), r.Next(25,225)); g.FillRectangle(sb, 0, 0, width, height); g.DrawString( "n o . "+st, fnt, Brushes.White, 10, 10); string name = top; for (int n = st.ToString().Length; n < fig; n++) name += "0"; name += st; string s = path + "/" + name + ext; img.Save(s, ifor); st++; } fnt.Dispose(); sb.Dispose(); g.Dispose(); img.Dispose(); } } public class Dialogue :Form { private IContainer components = null; public string path; public bool save = false; private int index = 0; private Label label_w; private Label label_h; private Label label_num; private Label label_top; private Label label_st; private Label label_1; private Label label_2; private Label label_fig; private Label label_for; public NumericUpDown nud_w; public NumericUpDown nud_h; public NumericUpDown nud_num; public NumericUpDown nud_st; public NumericUpDown nud_fig; public TextBox tb_top; private Button bt_directory; private Button bt_save; private Button bt_cancel; public ComboBox cb_for; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } public void Initialize(int width, int height, int num, int st, string top, int fig, string format) { Project project = (Project)PluginBase.CurrentProject; if (path == null) path = project.Directory; SuspendLayout(); nud_w = makeNUM("nud_w", new Point( 55, 36), new Size(65, 19), 5120, 0, width); nud_h = makeNUM("nud_h", new Point(180, 36), new Size(65, 19), 5120, 0, height); nud_num = makeNUM("nud_num", new Point( 54, 61), new Size(66, 19), 1000, 1, num); tb_top = makeTextBox("tb_top", new Point(80, 128), new Size(85, 19), top); String[] myst = new String[] { "png", "jpg", "gif", "bmp" }; cb_for = makeComboBox("cb_for", new Point(218, 128), new Size(51, 20), myst); cb_for.SelectedItem = format; nud_st = makeNUM("nud_st", new Point( 80, 153), new Size(85, 19), 10000, 0, st); nud_fig = makeNUM("nud_fig", new Point(218, 153), new Size(51, 19), 20, 1, fig); bt_directory = makeButton("bt_directory", new Point( 14, 201), new Size(75, 23), "保存先選択"); bt_save = makeButton("bt_save", new Point(113, 201), new Size(75, 23), "書き出し"); bt_cancel = makeButton("bt_cancel", new Point(194, 201), new Size(75, 23), "キャンセル"); label_w = makeLabel("label_w", new Point( 15, 38), new Size(35, 12), "横幅 :"); label_h = makeLabel("label_h", new Point(139, 38), new Size(35, 12), "縦幅 :"); label_num = makeLabel("label_num", new Point( 13, 63), new Size(35, 12), "枚数 :"); label_top = makeLabel("label_top", new Point( 15, 131), new Size(59, 12), "先頭文字 :"); label_st = makeLabel("label_st", new Point( 15, 155), new Size(59, 12), "開始番号 :"); label_1 = makeLabel("label_1", new Point( 12, 9), new Size(73, 12), "- 生成画像設定 -"); label_2 = makeLabel("label_2", new Point( 12, 100), new Size(95, 12), "- 書き出し設定 -"); label_fig = makeLabel("label_fig", new Point(177, 155), new Size(35, 12), "桁数 :"); label_for = makeLabel("label_for", new Point(177, 131), new Size(35, 12), "形式 :"); bt_directory.Click += new EventHandler(bt_directory_Click); bt_save.Click += new EventHandler(bt_save_Click); bt_cancel.Click += new EventHandler(bt_cancel_Click); AutoScaleDimensions = new SizeF(6F, 12F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(286, 241); Controls.Add(label_2); Controls.Add(label_1); Controls.Add(label_st); Controls.Add(label_top); Controls.Add(label_num); Controls.Add(label_h); Controls.Add(label_w); Controls.Add(label_fig); Controls.Add(label_for); Controls.Add(bt_cancel); Controls.Add(bt_save); Controls.Add(bt_directory); Controls.Add(tb_top); Controls.Add(nud_st); Controls.Add(nud_num); Controls.Add(nud_h); Controls.Add(nud_w); Controls.Add(nud_fig); Controls.Add(cb_for); FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; Name = "Dialogue"; ShowIcon = false; ShowInTaskbar = false; SizeGripStyle = SizeGripStyle.Hide; Text = "ダミー画像生成ツール"; ResumeLayout(false); PerformLayout(); } private void bt_directory_Click(object sender, EventArgs e) { selectDirectory(); } private void bt_save_Click(object sender, EventArgs e) { save = true; Close(); } private void bt_cancel_Click(object sender, EventArgs e) { save = false; Close(); } private void selectDirectory() { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "保存先のディレクトリを選んでください。"; fbd.SelectedPath = path; if (fbd.ShowDialog() == DialogResult.OK) { path = fbd.SelectedPath; } fbd.Dispose(); } private Label makeLabel(string name, Point pt, Size sz, string text) { Label lb = new Label(); lb.Name = name; lb.Location = pt; lb.Size = sz; lb.Text = text; lb.AutoSize = true; lb.TabIndex = index ++; return lb; } private NumericUpDown makeNUM(string name, Point pt, Size sz, int max, int min, int def) { NumericUpDown nud = new NumericUpDown(); ((ISupportInitialize)nud).BeginInit(); nud.Name = name; nud.Location = pt; nud.Size = sz; nud.Maximum = max; nud.Minimum = min; nud.Value = def; nud.TabIndex = index ++; ((ISupportInitialize)nud).EndInit(); return nud; } private Button makeButton(string name, Point pt, Size sz, string text) { Button bt = new Button(); bt.Name = name; bt.Location = pt; bt.Size = sz; bt.Text = text; bt.UseVisualStyleBackColor = true; bt.TabIndex = index ++; return bt; } private TextBox makeTextBox(string name, Point pt, Size sz, string text) { TextBox tb = new TextBox(); tb.Name = name; tb.Location = pt; tb.Size = sz; tb.Text = text; tb.TabIndex = index ++; return tb; } private ComboBox makeComboBox(string name, Point pt, Size sz, string[] st) { ComboBox cb = new ComboBox(); cb.FormattingEnabled = true; cb.Name = name; cb.Location = pt; cb.Size = sz; cb.Items.AddRange(st); cb.SelectedIndex = 0; cb.TabIndex = index++; return cb; } } }