diff --git a/src/wings_io.erl b/src/wings_io.erl index 94d8d8bd2..bddecddcf 100644 --- a/src/wings_io.erl +++ b/src/wings_io.erl @@ -410,8 +410,11 @@ gradient_rect_burst(X, Y, W, H, Color) -> GradColors = [0.882353, 0.882353, 0.850980, 0.807843, 0.776471, 0.729412, 0.701961, 0.666667, 0.619608, 0.741176, 0.733333, 0.760784, 0.784314, 0.811765, 0.854902, 0.890196, 0.890196], + K = if H=<17 -> H; + true -> H-1 + end, Draw_Line = fun(Idx) -> - GreyValue = lists:nth(round((Idx/H)*17)+1, GradColors), + GreyValue = lists:nth(trunc((Idx/K)*17)+1, GradColors), LineColor = mul_color(Color, GreyValue), set_color(LineColor), gl:vertex2f(X-0.5+W, Y-0.5+H-Idx), diff --git a/src/wings_msg.erl b/src/wings_msg.erl index b0dfa8bed..e586f4846 100644 --- a/src/wings_msg.erl +++ b/src/wings_msg.erl @@ -23,7 +23,7 @@ -include("wings.hrl"). -import(lists, [reverse/1]). --define(SEP, [$\s,$\s,160]). %Two and a half. +-define(SEP, [160,160,160,160,160]). %Equivalent to two and a half space character width. -define(CSEP, 160). %Short space. button(LmbMsg) -> diff --git a/src/wings_wm.erl b/src/wings_wm.erl index e2e77e4cb..108ec44cd 100644 --- a/src/wings_wm.erl +++ b/src/wings_wm.erl @@ -110,10 +110,12 @@ init() -> desktop_event(_) -> keep. message(Message) -> - wings_io:putback_event({wm,{message,get(wm_active),Message}}). + MsgData0=get_window_data(message), + put_window_data(message,MsgData0#win{z=highest_z()}), + wings_io:putback_event({wm,{message,get(wm_active),Message}}). message_right(Right) -> - wings_io:putback_event({wm,{message_right,get(wm_active),Right}}). + wings_io:putback_event({wm,{message_right,get(wm_active),Right}}). message(Message, Right) -> message(Message), @@ -899,10 +901,10 @@ wm_event({message,Name,Msg}) -> none -> ok; #win{stk=[#se{msg=Msg}|_]} -> ok; #win{stk=[Top0|Stk]}=Data0 -> - Top = Top0#se{msg=Msg}, - Data = Data0#win{stk=[Top|Stk]}, - put_window_data(Name, Data), - dirty() + Top = Top0#se{msg=Msg}, + Data = Data0#win{stk=[Top|Stk]}, + put_window_data(Name, Data), + dirty() end; wm_event({message_right,Name,Right0}) -> Right = lists:flatten(Right0), @@ -910,10 +912,10 @@ wm_event({message_right,Name,Right0}) -> none -> ok; #win{stk=[#se{msg_right=Right}|_]} -> ok; #win{stk=[Top0|Stk]}=Data0 -> - Top = Top0#se{msg_right=Right}, - Data = Data0#win{stk=[Top|Stk]}, - put_window_data(Name, Data), - dirty() + Top = Top0#se{msg_right=Right}, + Data = Data0#win{stk=[Top|Stk]}, + put_window_data(Name, Data), + dirty() end; wm_event({menubar,Name,Menubar}) -> case lookup_window_data(Name) of @@ -1156,8 +1158,9 @@ message_event(redraw) -> undefined -> keep; Active -> #win{stk=[#se{msg=Msg,msg_right=Right}|_]} = get_window_data(Active), - message_redraw(Msg, Right) - end; + Msg0=calculate_win_size(Msg,Right), + message_redraw(Msg0, Right) + end; message_event({action,_}=Action) -> send(geom, Action); message_event(got_focus) -> @@ -1176,6 +1179,7 @@ message_redraw(Msg, Right) -> {unix,darwin} -> 27; _ -> 0 end, + case Right of [] -> ok; _ -> @@ -1183,17 +1187,13 @@ message_redraw(Msg, Right) -> Cw = ?CHAR_WIDTH, CH = ?CHAR_HEIGHT, Lh = ?LINE_HEIGHT, - MsgW = wings_text:width(lists:flatten(Msg)), + RightW = wings_text:width(Right), RMarg = RMarg0 + 2*Cw, - if - MsgW+RightW < W - RMarg -> - Pos = W - RightW - RMarg, - wings_io:sunken_rect(Pos-12, -CH, RightW+12, Lh, Col, Col), - wings_io:set_color(wings_pref:get_value(info_line_text)), - wings_io:text_at(Pos-6, -1, Right); - true -> ok - end + Pos = W - RightW - RMarg, + wings_io:sunken_rect(Pos-12, -CH, RightW+12, Lh-1, Col, Col), + wings_io:set_color(wings_pref:get_value(info_line_text)), + wings_io:text_at(Pos-6, -1, Right) end, case OsType of {unix,darwin} -> @@ -1209,9 +1209,85 @@ message_setup() -> {W,H} = win_size(), wings_io:gradient_rect_burst(0, 0, W, H, wings_pref:get_value(info_line_bg)), wings_io:set_color(wings_pref:get_value(info_line_text)), - gl:translatef(10, H-5.375, 0), + gl:translatef(10, ?LINE_HEIGHT+2, 0), {W,H}. +calculate_win_size(Msg,Right) -> +% this '+24' came from message_redraw() used in 'sunken_rect' function + Right_W=wings_text:width(lists:flatten(Right))+24, + + OsType = get(wings_os_type), + RMarg0 = case OsType of + {unix,darwin} -> 27; + _ -> 0 + end, + + {Msg0,WinSize}=check_text_width(Msg,Right_W+RMarg0), + resize_msg_win(WinSize), + Msg0. + +resize_msg_win({X0,Y0,W0,H0}) -> + MsgData0=get_window_data(message), + put_window_data(message,MsgData0#win{x=X0,y=Y0,w=W0,h=H0}), + OldActive = put(wm_active, message), + {_,TopH} = get(wm_top_size), + Y = TopH-(Y0+H0), + ViewPort = {X0,Y,W0,H0}, + case put(wm_viewport, ViewPort) of + ViewPort -> ok; + _ -> gl:viewport(X0,Y,W0,H0) + end, + case OldActive of + undefined -> none; + _ -> put(wm_active, OldActive) + end. + +check_text_width(Msg,RightW) -> + {W,H0}=win_size(desktop), + MaxW=W-RightW, + Msg0=strip_lines(Msg,MaxW), + NrLn=count_lines(Msg0), + InfoH = case NrLn of + 1 -> ?LINE_HEIGHT; + _ -> round(NrLn*?LINE_HEIGHT) + end, + H=InfoH+trunc(?LINE_HEIGHT/2)-1, + Y = H0-InfoH+?CHAR_HEIGHT+2, + {Msg0,{0,Y,W,H}}. + +strip_lines(Msg,W) -> + Msg0=lists:flatten(Msg), + Tw=wings_text:width(Msg0), + if Tw= Msg; + true -> + break_line(Msg0,W) + end. + +break_line(Msg,W) -> + Msg0=split_msg(Msg,[]), + MsgSpl=string:tokens(Msg0," "), + {_,MsgSp2}=lists:foldl(fun(E,{WAcc,Acc}) -> + WAcc0 = WAcc+wings_text:width(E)+?CHAR_WIDTH, + if WAcc0>W -> + {0,Acc++[$\n]++E}; + true -> {WAcc0,Acc++E++[" "]} + end + end ,{0,[]}, MsgSpl), + MsgSp2. + +split_msg([],Acc) -> Acc; +split_msg([{_Fmt,_Txt}=H|T],Acc) -> + split_msg(T,Acc++[H]); +split_msg([H|T],Acc) -> + split_msg(T,Acc++[H]). + +count_lines([]) -> 1; +count_lines([$\n|S]) -> + count_lines(S)+1; +count_lines([_|S]) -> + count_lines(S). + + %%% %%% Toplevel: create a window and a controller window at the same time. %%% The controller adds a title bar (allowing the window to be moved) and diff --git a/src/wings_wm_toplevel.erl b/src/wings_wm_toplevel.erl index e6cd289c6..24d17be29 100644 --- a/src/wings_wm_toplevel.erl +++ b/src/wings_wm_toplevel.erl @@ -142,7 +142,7 @@ get_ctrl_event(Cs) -> {replace,fun(Ev) -> ctrl_event(Ev, Cs) end}. ctrl_event(redraw, Cs) -> - ctrl_message(), +% ctrl_message(), ctrl_redraw(Cs); ctrl_event(#mousebutton{button=1,state=?SDL_PRESSED}, #ctrl{state=moving,prev_focus=Focus}=Cs) ->