/tutorial/vision/multi_tasking/kitchen_clock.e
Specman e | 117 lines | 101 code | 13 blank | 3 comment | 3 complexity | 233058dc742d05fe8cf236b2f16007d2 MD5 | raw file
1class KITCHEN_CLOCK 2-- 3-- An old style kitchen clock. 4-- 5 6inherit 7 GRAPHIC 8 LAYOUT 9 redefine set_container 10 end 11 12creation {ANY} 13 default_create 14 15feature {} 16 pen1, pen2: DRAW_KIT 17 18feature {ANY} 19 w: WINDOW 20 21 set_container (c: CONTAINER) is 22 local 23 update: SIMPLE_PERIODIC_JOB 24 do 25 check 26 c /= Void 27 end 28 w ::= c 29 container := c 30 create pen1 31 create pen2 32 pen2.set_line_width(5) 33 pen2.set_color(magenta_color) 34 w.set_background_color(white_color) 35 w.set_requisition(10, 10, 30, 30) 36 create update.set_work(agent redraw, Void, 1, 1.0) 37 vision.loop_stack.add_job(update) 38 end 39 40 redo_layout (x, y: INTEGER) is 41 local 42 i: INTEGER; widget: WIDGET 43 do 44 from 45 i := container.child.upper 46 until 47 i < container.child.lower 48 loop 49 widget := container.child.item(i) 50 if not widget.valid_width(widget.width) or else not widget.valid_height(widget.height) then 51 widget.set_geometry(0, 20, widget.std_width, widget.std_height) 52 end 53 i := i - 1 54 end 55 end 56 57 update_requisition is 58 do 59 w.set_requisition(w.min_width, w.min_height, w.std_width, w.std_height) 60 end 61 62feature {CONTAINER} 63 expose_paint is 64 do 65 draw 66 end 67 68feature {} 69 draw is 70 local 71 time: TIME; angle: REAL_64; english_string: STRING 72 do 73 pen1.set_drawable(w) 74 pen2.set_drawable(w) 75 english_string := once " ... local private persistant buffer ... " 76 time.update 77 angle := (time.second - 15) / 60 * 2 * 3.1415926 78 pen2.line(w.width // 2, 79 w.height // 2, 80 w.width // 2 + (w.width / 2 * angle.cos).floor.force_to_integer_32, 81 w.height // 2 + (w.height / 2 * angle.sin).floor.force_to_integer_32) 82 angle := ((time.hour - 3) / 12 + time.minute / (60 * 12)) * 2 * 3.1415926 83 pen1.line(w.width // 2, 84 w.height // 2, 85 w.width // 2 + (w.width / 4 * angle.cos).floor.force_to_integer_32, 86 w.height // 2 + (w.height / 4 * angle.sin).floor.force_to_integer_32) 87 angle := (time.minute - 15) / 60 * 2 * 3.1415926 88 pen1.line(w.width // 2, 89 w.height // 2, 90 w.width // 2 + (w.width / 2 * angle.cos).floor.force_to_integer_32, 91 w.height // 2 + (w.height / 2 * angle.sin).floor.force_to_integer_32) 92 english_string.clear_count 93 time_formatter.set_time(time) 94 time_formatter.append_in(english_string) 95 unicode_string.clear_count 96 if unicode_string.utf8_decode_from(english_string) then 97 pen2.put_string(unicode_string, 0, 0) 98 end 99 end 100 101 time_formatter: TIME_FORMATTER is 102 once 103 create {TIME_IN_ENGLISH}Result 104 end 105 106 redraw: BOOLEAN is 107 do 108 w.clear 109 Result := True 110 end 111 112 unicode_string: UNICODE_STRING is 113 once 114 create Result.make(0) 115 end 116 117end -- class KITCHEN_CLOCK