Mercurial > hg > octave-nkf
comparison scripts/plot/findfigs.m @ 17477:f44839118b5f
findfigs.m: Overhaul function.
* scripts/plot/findfigs.m: Use 'hfigs' instead of 'figh' for list of figure
handles. Don't bother to test value before using set() since C++ code does
that already, and much faster. Recode for loop into a foreach style loop.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Sep 2013 08:12:35 -0700 |
parents | 1c89599167a6 |
children |
comparison
equal
deleted
inserted
replaced
17476:f0f4b524b6d0 | 17477:f44839118b5f |
---|---|
27 ## Author: Bill Denney <bill@denney.ws> | 27 ## Author: Bill Denney <bill@denney.ws> |
28 ## Modified by: Carnë Draug <carandraug+dev@gmail.com> | 28 ## Modified by: Carnë Draug <carandraug+dev@gmail.com> |
29 | 29 |
30 function findfigs () | 30 function findfigs () |
31 | 31 |
32 figh = allchild (0); | 32 hfigs = allchild (0); |
33 units = get (0, "units"); | 33 units = get (0, "units"); |
34 unwind_protect | 34 unwind_protect |
35 if (!strcmp (units, "pixels")) | 35 set (0, "units", "pixels"); |
36 set (0, "units", "pixels"); | |
37 endif | |
38 screensize = get (0, "screensize"); | 36 screensize = get (0, "screensize"); |
39 unwind_protect_cleanup | 37 unwind_protect_cleanup |
40 set (0, "units", units); | 38 set (0, "units", units); |
41 end_unwind_protect | 39 end_unwind_protect |
42 | 40 |
44 ## marginally be on the monitor. | 42 ## marginally be on the monitor. |
45 margin = 30; | 43 margin = 30; |
46 screensize(1:2) += margin; | 44 screensize(1:2) += margin; |
47 screensize(3:4) -= margin; | 45 screensize(3:4) -= margin; |
48 | 46 |
49 for i = 1:numel (figh) | 47 hfigs = hfigs(strcmp (get (hfigs, "visible"), "on")); |
50 if (strcmp (get (figh(i), "visible"), "on")) | 48 for hf = hfigs' |
49 units = get (hf, "units"); | |
50 unwind_protect | |
51 set (hf, "units", "pixels"); | |
52 pos = get (hf, "position"); | |
53 ## Test if (in order): | |
54 ## The left side is outside the right side of the screen | |
55 ## The bottom is above the top of the screen | |
56 ## The right side is outside the left of the screen | |
57 ## the top is below the bottom of the screen | |
58 if (pos(1) > screensize(3) | |
59 || pos(2) > screensize(4) | |
60 || pos(1)+pos(3) < screensize(1) | |
61 || pos(2)+pos(4) < screensize(2)) | |
51 | 62 |
52 units = get (figh(i), "units"); | 63 ## the new position will be at the top left of the screen |
53 unwind_protect | 64 ## (all moved figures will overlap). The bottom left is chosen |
54 if (!strcmp (units, "pixels")) | 65 ## instead of the top left because that allows for the unknown |
55 set (figh(i), "units", "pixels"); | 66 ## amount of space for the menu bar and the title bar. |
56 endif | 67 pos(1) = screensize(1); |
57 pos = get (figh(i), "position"); | 68 pos(2) = screensize(2); |
58 ## Test if (in order): | 69 set (hf, "position", pos); |
59 ## The left side is outside the right side of the screen | 70 endif |
60 ## The bottom is above the top of the screen | 71 unwind_protect_cleanup |
61 ## The right side is outside the left of the screen | 72 set (hf, "units", units); |
62 ## the top is below the bottom of the screen | 73 end_unwind_protect |
63 if (pos(1) > screensize(3) | 74 endfor |
64 || pos(2) > screensize(4) | |
65 || pos(1)+pos(3) < screensize(1) | |
66 || pos(2)+pos(4) < screensize(2)) | |
67 | 75 |
68 ## the new position will be at the top left of the screen | |
69 ## (all moved figures will overlap). The bottom left is chosen | |
70 ## instead of the top left because that allows for the unknown | |
71 ## amount of space for the menu bar and the title bar. | |
72 pos(1) = screensize(1); | |
73 pos(2) = screensize(2); | |
74 set (figh(i), "position", pos); | |
75 endif | |
76 unwind_protect_cleanup | |
77 set (figh(i), "units", units); | |
78 end_unwind_protect | |
79 endif | |
80 endfor | |
81 endfunction | 76 endfunction |
82 | 77 |