1### Copyright (c) 2007, Tyzx Corporation. All rights reserved.
2
3function g = g_locate (g, newloc)
4### g = g_locate (g, [posx, posy, width, height]) - Set the origin and size of g
5###
6### This function replaces all "set scale W,H" by  "set scale width*W,height*H"
7### and "set origin X,Y" by "set origin posx+height*X,posy+widthY".
8###
9### See also: g_new,...
10
11  _g_check (g);
12
13  ##printf ("Re-locating g at '%s'\n",g.dir);
14
15  found_origin = found_size = 0;
16  for i = 1:length (g.cmds)
17    [dums,dume,dumte,dumm,toks] = \
18	regexp (g.cmds{i}, '^set\s*(origin|size)\s*([^,\s]+)\s*,\s*([^,\s]+)');
19    if length (toks)
20      args = [str2num(toks{1}{2}), str2num(toks{1}{3})];
21
22      if     strcmp (toks{1}{1}, "origin")
23	found_origin = 1;
24	args = args .* newloc(3:4) + newloc(1:2);
25      elseif strcmp (toks{1}{1}, "size")
26	found_size =   1;
27	args = args .* newloc(3:4);
28      else
29	error ("First token isn't what I thought, but '%s'",toks{1}{1});
30      endif
31      g.cmds{i} = sprintf ("set %s %g,%g",toks{1}{1}, args);
32    endif
33  endfor
34
35  if ! found_size && any ((newloc(1:2)) || any (newloc(3:4)!= 1))
36    g.cmds = {sprintf("set size %g,%g",newloc(3:4)),\
37	     g.cmds{:}};
38  endif
39  if ! found_origin && any (newloc(3:4)!= 1)
40    g.cmds = {sprintf("set origin %g,%g",newloc(1:2)),\
41	     g.cmds{:}};
42  endif
43
44endfunction
45
46