home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / DEMO / COLOR_ED.LF < prev    next >
Text File  |  1996-06-04  |  5KB  |  199 lines

  1. % FILE. . . . . /usr/local-europa/hak/life/color_edit.lf
  2. % EDIT BY . . . Hassan Ait-Kaci
  3. % ON MACHINE. . Europa
  4. % STARTED ON. . Mon Apr 18 19:08:49 1994
  5.  
  6. % Last modified on Mon Nov 14 15:24:34 1994 by Hak
  7.  
  8. module("color_edit") ?
  9. public(color_edit) ?
  10.  
  11. import("xtools_utils")?
  12. open("xtools")?
  13.  
  14. persistent(main_panel) ?
  15. persistent(color_window) ?
  16.  
  17. global(quit)?
  18.  
  19. persistent(hue_step)? hue_step <<- 1?
  20.  
  21. persistent(r_value)? r_value <<- 0 ?
  22. persistent(g_value)? g_value <<- 0 ?
  23. persistent(b_value)? b_value <<- 0 ?
  24.  
  25. deep_box <| frame.
  26. deep_box <| field.
  27.  
  28. :: deep_box(frame_state => true).
  29.  
  30. set_up :-
  31.     H = 200,
  32.     
  33.     S1 = vsbar(H,B1,r), B1 = meterbox(S1,r),
  34.     S2 = vsbar(H,B2,g), B2 = meterbox(S2,g),
  35.     S3 = vsbar(H,B3,b), B3 = meterbox(S3,b),
  36.     
  37.     same_size([B1,B2,B3]),
  38.     
  39.     M1 = vc_list [S1,v_box(10),B1],
  40.     M2 = vc_list [S2,v_box(10),B2],
  41.     M3 = vc_list [S3,v_box(10),B3],
  42.     
  43.     Sliders = padded_box
  44.       (frame_box(hc_list [M1,h_box(10),M2,h_box(10),M3],
  45.              padding => P:10),
  46.        padding => P),
  47.     
  48.     Sliders = @(width => W),
  49.     
  50.     QuitButton = push_button(text => "Quit",
  51.                  action => quit_edit),
  52.  
  53.     StepButton = text_field_button(text => psi2str(hue_step),
  54.                        offset => 0,
  55.                        action => set_hue(StepButton)),
  56.  
  57.     Controls = vr_list [ frame_box(ColorBox,padding=>5),
  58.                  v_box(20),
  59.                  QuitButton,
  60.                  v_box(20),
  61.                  hc_list [ text_box(text => "Hue Step"),
  62.                        h_box(5),
  63.                        StepButton ]
  64.                ],
  65.  
  66.     ColorBox = deep_box(width => W,height => W/2),
  67.     
  68.     TitleBox = fancy_text_box
  69.       (text => Title:"Color Editor",
  70.        font => title_font,
  71.        colors => [red_color,green_color,blue_color]),
  72.     
  73.     Panel = panel(title => Title,
  74.               r_slider => S1.slider, r_meter => B1,
  75.               g_slider => S2.slider, g_meter => B2,
  76.               b_slider => S3.slider, b_meter => B3,
  77.               hue_button => StepButton,
  78.               color_box => ColorBox)
  79.       containing vc_list [v_box(10),
  80.                   hc_list [Sliders,h_box(10),Controls,h_box(20)],
  81.                   TitleBox,
  82.                   v_box(10)],
  83.     main_panel <<- Panel.
  84.  
  85. vsbar(Height,TextBox,Color) ->
  86.     v_slide_bar
  87.       (height => Height,
  88.        slider => S:v_slider(min => 0,
  89.                 max => 255,
  90.                 color => Color,
  91.                 color_id => c_id(Color),
  92.                 value => c_value(Color),
  93.                 action => set_meter(S,TextBox)))
  94.       containing S.
  95.  
  96. meterbox(SlideBar,Color) ->
  97.     B:text_field_button(height => H,
  98.                 width => H,
  99.                 text => "    ", %psi2str(c_value(Color)),
  100.                 offset => 0,
  101.                 action => set_color_slider(B,SlideBar.slider)).
  102.  
  103. set_color_slider(BT:@(text => T),
  104.        Slider:@(max => Max,min => Min,color => C)) :-
  105.     V = parse(T),
  106.     V :< real,
  107.     V >= Min,
  108.     V =< Max,
  109.     T <<- int2str(FV:round(V)),
  110.     refresh_look(BT),
  111.     move_slider(Slider,FV),
  112.     reset_color(C,FV),
  113.     write("red = ", c_value(r),
  114.           ", green = ", c_value(g),
  115.           ", blue = ", c_value(b)),
  116.     set_color_box(c_value(r),c_value(g),c_value(b)).
  117.  
  118. set_meter(@(color => C,value => V),BT:@(text => T)) :-
  119.     reset_color(C,FV),
  120.     set_color_box(c_value(r),c_value(g),c_value(b)),
  121.     T <<- int2str(FV:round(V)),
  122.     refresh_look(BT).
  123.  
  124. set_hue(HB:@(text => T)) :-
  125.     V = parse(T),
  126.     V :< real,
  127.     V >= Min,
  128.     V =< Max, !,
  129.     T <<- int2str(FV:floor(V)),
  130.     refresh_look(HB),
  131.     hue_step <<- FV.    
  132. set_hue(HB:@(text => T)) :-
  133.     beep,
  134.     write("Bad hue value -- must be a number!"),
  135.     nl,
  136.     T <<- psi2str(hue_step),
  137.     refresh_look(HB).
  138.  
  139. round(V) -> floor(V/hue_step)*hue_step.
  140.  
  141. c_value(r) -> copy_term(r_value).
  142. c_value(g) -> copy_term(g_value).
  143. c_value(b) -> copy_term(b_value).
  144.  
  145. c_id(r) -> red_color.
  146. c_id(g) -> green_color.
  147. c_id(b) -> blue_color.
  148.  
  149. reset_color(r,Value) :-    r_value <<- Value.
  150. reset_color(g,Value) :-    g_value <<- Value.
  151. reset_color(b,Value) :-    b_value <<- Value.
  152.  
  153. set_color_box(R,G,B) :-
  154.     Box = (main_panel.color_box) & @(X,Y,W,H),
  155.     Color = new_color(R,G,B),
  156.     xFillRectangle(color_window,X+1,Y+1,W-2,H-2,color => Color),
  157.     xFreeColor(color_window,Color).
  158.  
  159. def_font(title_font,
  160.      new_font(cond(life_demo#using_demo_fonts,
  161.                "terminal_bold_narrow28",
  162.                "-adobe-helvetica-bold-r-narrow--25-180-100-100-p-116-*")))?
  163.  
  164. def_color(main_colors,red_color,red)?
  165. def_color(main_colors,green_color,'lime green')?
  166. def_color(main_colors,blue_color,blue)?
  167.  
  168. def_color(highlight_colors,red_color,orange)?
  169. def_color(highlight_colors,green_color,'spring green')?
  170. def_color(highlight_colors,blue_color,'cornflower blue')?
  171.  
  172. def_color(shade_colors,red_color,maroon)?
  173. def_color(shade_colors,green_color,'dark green')?
  174. def_color(shade_colors,blue_color,'midnight blue')?
  175.  
  176. quit_edit :- set_choice(quit), fail.
  177.  
  178. init_panel(P) :-
  179.     color_window <<- P.color_box.mother.window,
  180.     HT = (HB:(P.hue_button)).text, HT <<- psi2str(hue_step),
  181.     refresh_look(HB),
  182.     move_slider(P.r_slider,R:c_value(r)),
  183.     TR = (RM:(P.r_meter)).text, TR <<- psi2str(R), refresh_look(RM),
  184.     move_slider(P.g_slider,G:c_value(g)),
  185.     TG = (GM:(P.g_meter)).text, TG <<- psi2str(G), refresh_look(GM),
  186.     move_slider(P.b_slider,B:c_value(b)),
  187.     TB = (BM:(P.b_meter)).text, TB <<- psi2str(B), refresh_look(BM),
  188.     set_color_box(R,G,B).
  189.  
  190. color_edit :-
  191.     set_up,
  192.     ( quit = get_choice,
  193.       create_box(P:copy_term(main_panel)),
  194.       init_panel(P)
  195.     ;
  196.       succeed
  197.     ).
  198.  
  199.