PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/vision/widget/colors.e

http://github.com/tybor/Liberty
Specman e | 179 lines | 146 code | 17 blank | 16 comment | 3 complexity | 417aa21c2393947230c190ad7d14a26f MD5 | raw file
  1class COLORS
  2	-- This example show COLORS from the list and produce color_list.e file
  3
  4inherit
  5	GRAPHIC
  6
  7insert
  8	ARGUMENTS
  9
 10creation {ANY}
 11	make
 12
 13feature {}
 14	scroll: SCROLL_VIEW
 15
 16	make is
 17		local
 18			main_window: TOPLEVEL_WINDOW; color_list: SUB_WINDOW; line: HORIZONTAL_LINE
 19		do
 20			if argument_count /= 1 then
 21				io.put_string("Give the color list file name as parameter.%N")
 22				io.put_string("You may use SmartEiffel/lib/vision/color/small_color_list.txt%N")
 23			else
 24				create main_window
 25				-- The default layout is column.
 26				create scroll.make(main_window)
 27				scroll.set_x_expand(True)
 28				scroll.set_y_expand(True)
 29				scroll.map
 30				create color_list.make_layout(scroll, create {COLUMN_LAYOUT})
 31				color_list.set_x_expand(True)
 32				color_list.set_y_expand(True)
 33				color_list.set_background_color(white_color)
 34				color_list.layout_pause
 35				add_colors(color_list, argument(1))
 36				color_list.layout_continue
 37				color_list.map
 38				color_list.when_left_down(agent set_move(True))
 39				color_list.when_left_up(agent set_move(False))
 40				color_list.when_pointer_move(agent moving)
 41				create line
 42				main_window.child_attach(line)
 43				add_controls(main_window)
 44				main_window.set_title("Scroll example")
 45				main_window.set_background_color(white_color)
 46				main_window.map
 47				vision.start
 48			end
 49		end
 50
 51	add_controls (w: WINDOW) is
 52		local
 53			controls: CONTAINER; layout: ROW_LAYOUT; quit: BUTTON; shift: BUTTON
 54		do
 55			create layout
 56			create controls.make_layout(w, layout)
 57			controls.set_x_expand(True)
 58			layout.set_border(5)
 59			layout.set_spacing(5)
 60			layout.insert_button_space
 61			create shift.with_label(controls, U"up")
 62			shift.when_left_clicked(agent scroll.vertical_shift(-50))
 63			create shift.with_label(controls, U"down")
 64			shift.when_left_clicked(agent scroll.vertical_shift(50))
 65			create shift.with_label(controls, U"left")
 66			shift.when_left_clicked(agent scroll.horizontal_shift(-20))
 67			create shift.with_label(controls, U"right")
 68			shift.when_left_clicked(agent scroll.horizontal_shift(20))
 69			layout.insert_button_space
 70			create quit.with_label(controls, U"Exit")
 71			quit.when_left_clicked(agent vision.loop_stack.break)
 72		end
 73
 74	move: BOOLEAN
 75
 76	click_x, click_y: INTEGER
 77
 78	set_move (b: BOOLEAN) is
 79		do
 80			move := b
 81			click_x := vision.pointer_x_root
 82			click_y := vision.pointer_y_root
 83		end
 84
 85	moving (x, y: INTEGER) is
 86		do
 87			if move then
 88				scroll.shift(vision.pointer_x_root - click_x, vision.pointer_y_root - click_y)
 89				click_x := vision.pointer_x_root
 90				click_y := vision.pointer_y_root
 91			end
 92		end
 93
 94	add_colors (c: CONTAINER; file_name: STRING) is
 95		local
 96			txt: TEXT_FILE_READ; class_file: TEXT_FILE_WRITE; r, g, b: INTEGER
 97		do
 98			create txt.connect_to(file_name)
 99			if txt.is_connected then
100				create class_file.connect_to("new_color_list.e")
101				class_file.put_string(header)
102				from
103					txt.read_integer
104					r := txt.last_integer
105				until
106					txt.end_of_input
107				loop
108					txt.read_integer
109					g := txt.last_integer
110					txt.read_integer
111					b := txt.last_integer
112					txt.skip_separators
113					txt.read_line
114					show_color(c, r, g, b, txt.last_string)
115					txt.last_string.to_lower
116					txt.last_string.replace_all(' ', '_')
117					txt.last_string.append(once "_color")
118					write(class_file, r, g, b, txt.last_string)
119					txt.read_integer
120					r := txt.last_integer
121				end
122				class_file.put_string("end%N")
123				class_file.disconnect
124				txt.disconnect
125			end
126		end
127
128	write (output: OUTPUT_STREAM; r, g, b: INTEGER; name: STRING) is
129		do
130			output.put_string(once "   ")
131			output.put_string(name)
132			output.put_string(once ": COLOR is%N      once%N	 create Result.like_rgb_8(")
133			output.put_integer(r)
134			output.put_character(',')
135			output.put_integer(g)
136			output.put_character(',')
137			output.put_integer(b)
138			output.put_string(once ")%N      end%N%N")
139		end
140
141	show_color (c: CONTAINER; r, g, b: INTEGER; name: STRING) is
142		local
143			label: LABEL; color: COLOR; item: CONTAINER; rect: FILL_RECTANGLE
144		do
145			create item.make_layout(c, create {ROW_LAYOUT})
146			create color.like_rgb_8(r, g, b)
147			create rect.make(10, 10, 100, 30)
148			rect.set_style(create {DRAW_STYLE})
149			rect.style.set_color(color)
150			item.set_x_expand(True)
151			item.child_attach(rect)
152			create label.make(create {UNICODE_STRING}.from_utf8(name))
153			item.child_attach(label)
154		end
155
156	header: STRING is "[
157-- This file is  free  software, which  comes  along  with  SmartEiffel. This
158-- software  is  distributed  in the hope that it will be useful, but WITHOUT
159-- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
160-- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
161-- this header is kept unaltered, and a notification of the changes is added.
162-- You  are  allowed  to  redistribute  it and sell it, alone or as a part of
163-- another product.
164--       Copyright (C) 1994-2002 LORIA - INRIA - U.H.P. Nancy 1 - FRANCE
165--          Philippe RIBET and Dominique COLNET - SmartEiffel@loria.fr
166--                       http://SmartEiffel.loria.fr
167--
168class COLOR_LIST
169--
170-- THIS FILE WAS GENERATED. DON'T EDIT
171--
172insert
173	ANY
174feature {}
175
176
177]"
178
179end -- class COLORS