aboutsummaryrefslogtreecommitdiffstats
path: root/lib/observer/src/observer_app_wx.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/observer/src/observer_app_wx.erl')
-rw-r--r--lib/observer/src/observer_app_wx.erl95
1 files changed, 59 insertions, 36 deletions
diff --git a/lib/observer/src/observer_app_wx.erl b/lib/observer/src/observer_app_wx.erl
index cb5f8c1259..900fba911a 100644
--- a/lib/observer/src/observer_app_wx.erl
+++ b/lib/observer/src/observer_app_wx.erl
@@ -27,6 +27,12 @@
-include_lib("wx/include/wx.hrl").
-include("observer_defs.hrl").
+%% Import drawing wrappers
+-import(observer_perf_wx, [haveGC/1,
+ setPen/2, setFont/3, setBrush/2,
+ strokeLine/5, strokeLines/2, drawRoundedRectangle/6,
+ drawText/4, getTextExtent/2]).
+
-record(state,
{
parent,
@@ -37,7 +43,8 @@
current,
app,
sel,
- appmon
+ appmon,
+ usegc = false
}).
-record(paint, {font, pen, brush, sel, links}).
@@ -102,8 +109,11 @@ init([Notebook, Parent]) ->
wxPanel:connect(DrawingArea, left_dclick),
wxPanel:connect(DrawingArea, right_down),
- %% DefFont = wxSystemSettings:getFont(?wxSYS_DEFAULT_GUI_FONT),
- DefFont = wxFont:new(12,?wxFONTFAMILY_DECORATIVE,?wxFONTSTYLE_NORMAL,?wxFONTWEIGHT_NORMAL),
+ UseGC = haveGC(DrawingArea),
+ Font = case UseGC of
+ true -> wxSystemSettings:getFont(?wxSYS_DEFAULT_GUI_FONT);
+ false -> wxFont:new(12,?wxFONTFAMILY_DECORATIVE,?wxFONTSTYLE_NORMAL,?wxFONTWEIGHT_NORMAL)
+ end,
SelCol = wxSystemSettings:getColour(?wxSYS_COLOUR_HIGHLIGHT),
GreyBrush = wxBrush:new({230,230,240}),
SelBrush = wxBrush:new(SelCol),
@@ -113,7 +123,8 @@ init([Notebook, Parent]) ->
panel =Panel,
apps_w=Apps,
app_w =DrawingArea,
- paint=#paint{font = DefFont,
+ usegc = UseGC,
+ paint=#paint{font = Font,
pen = wxPen:new({80,80,80}, [{width, 2}]),
brush= GreyBrush,
sel = SelBrush,
@@ -218,16 +229,23 @@ handle_event(Event, _State) ->
%%%%%%%%%%
handle_sync_event(#wx{event = #wxPaint{}},_,
- #state{app_w=DA, app=App, sel=Sel, paint=Paint}) ->
+ #state{app_w=DA, app=App, sel=Sel, paint=Paint, usegc=UseGC}) ->
%% PaintDC must be created in a callback to work on windows.
DC = wxPaintDC:new(DA),
- GC = ?wxGC:create(DC),
- %% Argh must handle scrolling when using ?wxGC
- {Sx,Sy} = wxScrolledWindow:calcScrolledPosition(DA, {0,0}),
- ?wxGC:translate(GC, Sx,Sy),
+ GC = case UseGC of
+ true ->
+ GC0 = ?wxGC:create(DC),
+ %% Argh must handle scrolling when using ?wxGC
+ {Sx,Sy} = wxScrolledWindow:calcScrolledPosition(DA, {0,0}),
+ ?wxGC:translate(GC0, Sx,Sy),
+ GC0;
+ false ->
+ wxScrolledWindow:doPrepareDC(DA,DC),
+ DC
+ end,
%% Nothing is drawn until wxPaintDC is destroyed.
- draw(GC, App, Sel, Paint),
- ?wxGC:destroy(GC),
+ draw({UseGC, GC}, App, Sel, Paint),
+ UseGC andalso ?wxGC:destroy(GC),
wxPaintDC:destroy(DC),
ok.
%%%%%%%%%%
@@ -274,12 +292,17 @@ handle_info({delivery, _Pid, app, _Curr, {[], [], [], []}},
{noreply, State#state{app=undefined, sel=undefined}};
handle_info({delivery, Pid, app, Curr, AppData},
- State = #state{panel=Panel, appmon=Pid, current=Curr,
+ State = #state{panel=Panel, appmon=Pid, current=Curr, usegc=UseGC,
app_w=AppWin, paint=#paint{font=Font}}) ->
- GC = ?wxGC:create(AppWin),
- ?wxGC:setFont(GC, Font, {0,0,0}),
- App = build_tree(AppData, {GC,Font}),
- ?wxGC:destroy(GC),
+ GC = if UseGC -> ?wxGC:create(AppWin);
+ true -> wxWindowDC:new(AppWin)
+ end,
+ FontW = {UseGC, GC},
+ setFont(FontW, Font, {0,0,0}),
+ App = build_tree(AppData, FontW),
+ if UseGC -> ?wxGC:destroy(GC);
+ true -> wxWindowDC:destroy(GC)
+ end,
setup_scrollbar(AppWin, App),
wxWindow:refresh(Panel),
wxWindow:layout(Panel),
@@ -374,11 +397,11 @@ locate_box(From, []) -> {false, From}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-build_tree({Root, P2Name, Links, XLinks0}, Font) ->
+build_tree({Root, P2Name, Links, XLinks0}, FontW) ->
Fam = sofs:relation_to_family(sofs:relation(Links)),
Name2P = gb_trees:from_orddict(lists:sort([{Name,Pid} || {Pid,Name} <- P2Name])),
Lookup = gb_trees:from_orddict(sofs:to_external(Fam)),
- {_, Tree0} = build_tree2(Root, Lookup, Name2P, Font),
+ {_, Tree0} = build_tree2(Root, Lookup, Name2P, FontW),
{Tree, Dim} = calc_tree_size(Tree0),
Fetch = fun({From, To}, Acc) ->
try {value, ToPid} = gb_trees:lookup(To, Name2P),
@@ -391,18 +414,18 @@ build_tree({Root, P2Name, Links, XLinks0}, Font) ->
XLinks = lists:foldl(Fetch, [], XLinks0),
#app{ptree=Tree, dim=Dim, links=XLinks}.
-build_tree2(Root, Tree0, N2P, Font) ->
+build_tree2(Root, Tree0, N2P, FontW) ->
case gb_trees:lookup(Root, Tree0) of
- none -> {Tree0, {box(Root, N2P, Font), []}};
+ none -> {Tree0, {box(Root, N2P, FontW), []}};
{value, Children} ->
Tree1 = gb_trees:delete(Root, Tree0),
{Tree, CHs} = lists:foldr(fun("port " ++_, Acc) ->
Acc; %% Skip ports
(Child,{T0, Acc}) ->
- {T, C} = build_tree2(Child, T0, N2P, Font),
+ {T, C} = build_tree2(Child, T0, N2P, FontW),
{T, [C|Acc]}
end, {Tree1, []}, Children),
- {Tree, {box(Root, N2P, Font), CHs}}
+ {Tree, {box(Root, N2P, FontW), CHs}}
end.
calc_tree_size(Tree) ->
@@ -447,12 +470,12 @@ middle([{#box{y=Y0},_}|List], _) ->
{#box{y=Y1},_} = lists:last(List),
(Y0+Y1) div 2.
-box(Str0, N2P, {Win,_Font}) ->
+box(Str0, N2P, FontW) ->
Pid = gb_trees:get(Str0, N2P),
Str = if hd(Str0) =:= $< -> lists:append(io_lib:format("~w", [Pid]));
true -> Str0
end,
- {TW,TH, _, _} = ?wxGC:getTextExtent(Win, Str),
+ {TW,TH} = getTextExtent(FontW, Str),
Data = #str{text=Str, x=?BX_HE, y=?BY_HE, pid=Pid},
%% Add pid
#box{w=round(TW)+?BX_E, h=round(TH)+?BY_E, s1=Data}.
@@ -473,30 +496,30 @@ draw(_DC, undefined, _, _) ->
ok;
draw(DC, #app{dim={_W,_H}, ptree=Tree, links=Links}, Sel,
#paint{font=Font, pen=Pen, brush=Brush, links=LPen, sel=SelBrush}) ->
- ?wxGC:setPen(DC, LPen),
+ setPen(DC, LPen),
[draw_xlink(Link, DC) || Link <- Links],
- ?wxGC:setPen(DC, Pen),
+ setPen(DC, Pen),
%% ?wxGC:drawRectangle(DC, 2,2, _W-2,_H-2), %% DEBUG
- ?wxGC:setBrush(DC, Brush),
- ?wxGC:setFont(DC, Font, {0,0,0}),
+ setBrush(DC, Brush),
+ setFont(DC, Font, {0,0,0}),
draw_tree(Tree, root, DC),
case Sel of
undefined -> ok;
{#box{x=X,y=Y,w=W,h=H,s1=Str1}, _} ->
- ?wxGC:setBrush(DC, SelBrush),
- ?wxGC:drawRoundedRectangle(DC, X-1,Y-1, W+2,H+2, 8.0),
+ setBrush(DC, SelBrush),
+ drawRoundedRectangle(DC, X-1,Y-1, W+2,H+2, 8.0),
draw_str(DC, Str1, X, Y)
end.
draw_tree({Box=#box{x=X,y=Y,w=W,h=H,s1=Str1}, Chs}, Parent, DC) ->
- ?wxGC:drawRoundedRectangle(DC, X,Y, W,H, 8.0),
+ drawRoundedRectangle(DC, X,Y, W,H, 8.0),
draw_str(DC, Str1, X, Y),
Dot = case Chs of
[] -> ok;
[{#box{x=CX0},_}|_] ->
CY = Y+(H div 2),
CX = CX0-(?BB_X div 2),
- ?wxGC:strokeLine(DC, X+W, CY, CX, CY),
+ strokeLine(DC, X+W, CY, CX, CY),
{CX, CY}
end,
draw_link(Parent, Box, DC),
@@ -506,9 +529,9 @@ draw_link({CX,CY}, #box{x=X,y=Y0,h=H}, DC) ->
Y = Y0+(H div 2),
case Y =:= CY of
true ->
- ?wxGC:strokeLine(DC, CX, CY, X, CY);
+ strokeLine(DC, CX, CY, X, CY);
false ->
- ?wxGC:strokeLines(DC, [{CX, CY}, {CX, Y}, {X,Y}])
+ strokeLines(DC, [{CX, CY}, {CX, Y}, {X,Y}])
end;
draw_link(_, _, _) -> ok.
@@ -527,8 +550,8 @@ draw_xlink(X0, Y00, X1, Y11, BH, DC) ->
{Y0,Y1} = if Y00 < Y11 -> {Y00+BH-6, Y11+6};
true -> {Y00+6, Y11+BH-6}
end,
- ?wxGC:strokeLines(DC, [{X0,Y0}, {X0+5,Y0}, {X1-5,Y1}, {X1,Y1}]).
+ strokeLines(DC, [{X0,Y0}, {X0+5,Y0}, {X1-5,Y1}, {X1,Y1}]).
draw_str(DC, #str{x=Sx,y=Sy, text=Text}, X, Y) ->
- ?wxGC:drawText(DC, Text, X+Sx,Y+Sy);
+ drawText(DC, Text, X+Sx,Y+Sy);
draw_str(_, _, _, _) -> ok.