1 | function uic = makeFlexDivider( parent, position, bgCol, orientation, showMarks ) |
---|
2 | %makeFlexDivider Create a divider widget and add markings if desired |
---|
3 | % |
---|
4 | % This function is for internal use only. |
---|
5 | % |
---|
6 | % See also: uiextras.VBoxFlex |
---|
7 | % uiextras.HBoxFlex |
---|
8 | % uiextras.GridFlex |
---|
9 | |
---|
10 | % Copyright 2010 The MathWorks, Inc. |
---|
11 | % 1.1 |
---|
12 | % 2012/05/08 08:02:58 |
---|
13 | |
---|
14 | error( nargchk( 5, 5, nargin, 'struct' ) ); |
---|
15 | |
---|
16 | if strcmpi( showMarks, 'off' ) || position(3)<3 || position(4)<3 |
---|
17 | % No amarkings or too small to show them, so draw a blank |
---|
18 | cdata = ones( position(4)-1, position(3)-1 ); % One less than the space since uicontrols always start with a blank pixel |
---|
19 | cdata = cat( 3, cdata*bgCol(1), cdata*bgCol(2), cdata*bgCol(3) ); |
---|
20 | else |
---|
21 | |
---|
22 | % Make the divider slightly darker than it's surroundings |
---|
23 | bgCol = 0.97*bgCol; |
---|
24 | |
---|
25 | % Determine the highlight and lowlight colors and create an empty image |
---|
26 | hiCol = 1-0.2*(1-bgCol); |
---|
27 | loCol = 0.8*bgCol; |
---|
28 | fgCol = 1-0.7*(1-bgCol); |
---|
29 | cdata = ones( position(4)-1, position(3)-1 ); % One less than the space since uicontrols always start with a blank pixel |
---|
30 | cdata = cat( 3, cdata*bgCol(1), cdata*bgCol(2), cdata*bgCol(3) ); |
---|
31 | |
---|
32 | % Fill central region with foreground color. Note that the top and left get |
---|
33 | % a spare pixel anyway, so start at 1,1. |
---|
34 | cdata(1:end-1,1:end-1,1) = fgCol(1); |
---|
35 | cdata(1:end-1,1:end-1,2) = fgCol(2); |
---|
36 | cdata(1:end-1,1:end-1,3) = fgCol(3); |
---|
37 | |
---|
38 | % Add fletchings if there's space |
---|
39 | if strcmpi( orientation, 'Vertical' ) |
---|
40 | % Vertical divider requires horizontal fletchings |
---|
41 | numFletches = min( 10, floor( position(4)/6 ) ); % Fill no more than half the space (3 pixels per mark, so divide by 6) |
---|
42 | y0 = round( (position(4)-numFletches*3 ) / 2 ); |
---|
43 | for ii=1:numFletches |
---|
44 | y = y0+(ii-1)*3; |
---|
45 | % Add highlight |
---|
46 | cdata(y,1:end-1,1) = hiCol(1); |
---|
47 | cdata(y,1:end-1,2) = hiCol(2); |
---|
48 | cdata(y,1:end-1,3) = hiCol(3); |
---|
49 | % Add shadow |
---|
50 | cdata(y+1,1:end-1,1) = loCol(1); |
---|
51 | cdata(y+1,1:end-1,2) = loCol(2); |
---|
52 | cdata(y+1,1:end-1,3) = loCol(3); |
---|
53 | end |
---|
54 | else |
---|
55 | % Horizontal divider requires vertical fletchings |
---|
56 | numFletches = min( 10, floor( position(3)/6 ) ); % Fill no more than half the space (3 pixels per mark, so divide by 6) |
---|
57 | x0 = round( (position(3)-numFletches*3 ) / 2 ); |
---|
58 | for ii=1:numFletches |
---|
59 | x = x0+(ii-1)*3; |
---|
60 | % Add highlight |
---|
61 | cdata(1:end-1,x,1) = hiCol(1); |
---|
62 | cdata(1:end-1,x,2) = hiCol(2); |
---|
63 | cdata(1:end-1,x,3) = hiCol(3); |
---|
64 | % Add shadow |
---|
65 | cdata(1:end-1,x+1,1) = loCol(1); |
---|
66 | cdata(1:end-1,x+1,2) = loCol(2); |
---|
67 | cdata(1:end-1,x+1,3) = loCol(3); |
---|
68 | end |
---|
69 | |
---|
70 | end |
---|
71 | end |
---|
72 | |
---|
73 | % If the first argument is a divider, we update it, otherwise create from |
---|
74 | % scratch. |
---|
75 | if strcmpi( get( parent, 'Type' ), 'UIControl' ) |
---|
76 | % Update existing |
---|
77 | set( parent, ... |
---|
78 | 'BackgroundColor', bgCol, ... |
---|
79 | 'ForegroundColor', bgCol, ... |
---|
80 | 'CData', cdata, ... |
---|
81 | 'Position', position ); |
---|
82 | uic = parent; |
---|
83 | else |
---|
84 | % Create the widget |
---|
85 | uic = uicontrol( 'Parent', parent, ... |
---|
86 | 'Style', 'Checkbox', ... |
---|
87 | 'BackgroundColor', bgCol, ... |
---|
88 | 'ForegroundColor', bgCol, ... |
---|
89 | 'CData', cdata, ... |
---|
90 | 'HitTest', 'on', ... |
---|
91 | 'Enable', 'inactive', ... |
---|
92 | 'Units', 'Pixels', ... |
---|
93 | 'Position', position, ... |
---|
94 | 'HandleVisibility', 'off' ); |
---|
95 | end |
---|
96 | |
---|
97 | % Store the original position for later |
---|
98 | setappdata( uic, 'OriginalPosition', position ); |
---|