Check-in [b6026abfcf]
Not logged in
Overview
SHA1 Hash:b6026abfcf4b7f1c07603edd0e8a56c78d2c0daf
Date: 2012-07-15 22:24:12
User: kinaba
Comment:Simplified GUI code.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified src/gui.d from [9f0067d733f090c1] to [a1f9b7cabb9073dd].

9 { 9 { 10 this.solver = new Solver(g); 10 this.solver = new Solver(g); 11 setup_size(g.map.W, g.map.H); 11 setup_size(g.map.W, g.map.H); 12 setup_resources(g); 12 setup_resources(g); 13 draw(g); 13 draw(g); 14 } 14 } 15 15 16 private void delegate(char c) fn; | 16 void run(void delegate(char c) command, bool automate = true) 17 void set_fn(F)(F f) { this.fn = f; } < 18 < 19 void run(bool automate = false) < 20 { 17 { 21 if(automate) { 18 if(automate) { 22 Timer t = new Timer; 19 Timer t = new Timer; 23 t.interval = 50; 20 t.interval = 50; 24 t.tick ~= (Timer sender, EventArgs ea){ < 25 fn(solver.single_step()); | 21 t.tick ~= (Timer s, EventArgs e){command(solver.single_s 26 }; < 27 t.start(); 22 t.start(); 28 this.closing ~= (Form f,CancelEventArgs c){t.stop();}; 23 this.closing ~= (Form f,CancelEventArgs c){t.stop();}; 29 } else { 24 } else { 30 setup_keyhandling(); | 25 setup_keyhandling(command); 31 } 26 } 32 Application.run(this); 27 Application.run(this); 33 } 28 } 34 29 35 override void on_game_changed(char c, in Game g, bool finished) 30 override void on_game_changed(char c, in Game g, bool finished) 36 { 31 { 37 draw(g); 32 draw(g); 38 } 33 } 39 34 40 private: 35 private: 41 int cell; < 42 < 43 void setup_size(int W, int H) 36 void setup_size(int W, int H) 44 { 37 { 45 this.formBorderStyle = FormBorderStyle.FIXED_DIALOG; 38 this.formBorderStyle = FormBorderStyle.FIXED_DIALOG; 46 this.maximizeBox = false; 39 this.maximizeBox = false; 47 this.minimizeBox = false; 40 this.minimizeBox = false; 48 this.cell = min(1024/W, 640/H); 41 this.cell = min(1024/W, 640/H); 49 this.clientSize = Size(W*cell, H*cell); 42 this.clientSize = Size(W*cell, H*cell); 50 } 43 } 51 44 > 45 int cell; 52 Font font; 46 Font font; 53 Color[char] colors; 47 Color[char] colors; 54 string[char] render; 48 string[char] render; 55 Graphics graphicContext; 49 Graphics graphicContext; 56 50 57 void setup_resources(in Game g) 51 void setup_resources(in Game g) 58 { 52 { ................................................................................................................................................................................ 81 this.render['\\'] = "λ"; 75 this.render['\\'] = "λ"; 82 this.render['R'] = "☃"; 76 this.render['R'] = "☃"; 83 this.render['d'] = "☠"; 77 this.render['d'] = "☠"; 84 this.render['L'] = "☒"; 78 this.render['L'] = "☒"; 85 this.render['O'] = "☐"; 79 this.render['O'] = "☐"; 86 this.render['W'] = "ꔣ"; 80 this.render['W'] = "ꔣ"; 87 this.render['!'] = "✄"; 81 this.render['!'] = "✄"; 88 foreach(c,tp; g.map.tr_target) { | 82 foreach(c,tp; g.map.tr_target) this.render[c] = [cast(dchar)('☢' 89 char d = g.map[tp]; < 90 this.render[c] = [cast(dchar)('☢'+d-'1')].to!string(); < 91 } < 92 foreach(char c; '1'..':') this.render[c] = [cast(dchar)('☢'+c-'1 | 83 foreach(char c; '1'..':') this.render[c] = [cast(dchar)('☢' 93 this.paint ~= (Control c, PaintEventArgs ev) { 84 this.paint ~= (Control c, PaintEventArgs ev) { 94 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 85 graphicContext.copyTo(ev.graphics, Rect(0,0,this.clientS 95 }; 86 }; 96 } 87 } 97 88 98 void draw(in Game g) 89 void draw(in Game g) 99 { 90 { ................................................................................................................................................................................ 126 " Tide: ", g.water_until_rise, 117 " Tide: ", g.water_until_rise, 127 " Wadler: ", g.hige_until_rise, 118 " Wadler: ", g.hige_until_rise, 128 " Razor: ", g.map.razor); 119 " Razor: ", g.map.razor); 129 invalidate(); 120 invalidate(); 130 } 121 } 131 122 132 private: 123 private: 133 void setup_keyhandling() | 124 void setup_keyhandling(void delegate(char c) command) 134 { 125 { 135 noMessageFilter(); 126 noMessageFilter(); 136 this.keyDown ~= &my_keydown; | 127 this.keyDown ~= (Control c, KeyEventArgs ev) { 137 } < 138 < 139 void do_manual_command(char c) | 128 void do_manual_command(char c) 140 { | 129 { 141 solver.force(c); | 130 solver.force(c); 142 fn(c); | 131 command(c); 143 } | 132 } 144 < 145 void my_keydown(Control c, KeyEventArgs ev) < 146 { < 147 switch(ev.keyCode) | 133 switch(ev.keyCode) 148 { | 134 { 149 case Keys.DOWN: do_manual_command('D'); break; | 135 case Keys.DOWN: do_manual_command('D'); break; 150 case Keys.UP: do_manual_command('U'); break; | 136 case Keys.UP: do_manual_command('U'); break; 151 case Keys.LEFT: do_manual_command('L'); break; | 137 case Keys.LEFT: do_manual_command('L'); break; 152 case Keys.RIGHT: do_manual_command('R'); break; | 138 case Keys.RIGHT: do_manual_command('R'); break; 153 case Keys.W: do_manual_command('W'); break; | 139 case Keys.W: do_manual_command('W'); break; 154 case Keys.S: do_manual_command('S'); break; | 140 case Keys.S: do_manual_command('S'); break; 155 case Keys.A: do_manual_command('A'); break; | 141 case Keys.A: do_manual_command('A'); break; 156 case Keys.G: fn(solver.single_step()); break; | 142 case Keys.G: command(solver.single_step()); break; 157 default: break; | 143 default: break; 158 } | 144 } > 145 }; 159 } 146 } 160 147 161 Solver solver; 148 Solver solver; 162 } 149 }

Modified src/gui_main.d from [05082d0f328d756c] to [4375fba2fc66f9ab].

> 1 import util; 1 import gui; 2 import gui; 2 import output; 3 import output; 3 import driver; 4 import driver; 4 import solver; 5 import solver; 5 import std.stdio; 6 import std.stdio; 6 pragma(lib, "dfl.lib"); 7 pragma(lib, "dfl.lib"); 7 8 8 void main(string[] args) | 9 void main(string[] argv) 9 { 10 { > 11 bool automate = (argv.length>=2 && std.string.indexOf(argv[1],"auto")>=0 > 12 10 Driver d = new Driver(stdin); | 13 auto d = new Driver(stdin); 11 d.addObserver!(GuardedOutput)(); 14 d.addObserver!(GuardedOutput)(); 12 auto g = d.addObserver!(GUI!MainSolver)(); | 15 d.addObserver!(GUI!MainSolver)().run(&d.command, automate); 13 g.set_fn(&d.command); < 14 g.run(); < 15 } 16 }