summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/metauml/metauml_note.mp
blob: 92d0aac93b9013e14e09e29e531387ff83aed788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
% MetaUML, a MetaPost library for typesetting exquisite UML diagrams.
% Copyright (C) 2005 Ovidiu Gheorghies
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

if known _metauml_note_mp:
  expandafter endinput
fi;
_metauml_note_mp:=1;

% def metauml_note_debug text txt=log txt enddef;
def metauml_note_debug text txt= enddef;

input metauml_defaults;
input util_log;

input util_object;
input util_picture_stack;
input util_shade;
input util_margins;

vardef NoteInfo@#=
  attributes(@#);
  var(color)   foreColor, borderColor;
  var(numeric) horizontalFolding, verticalFolding;

  FontInfo.@#iFont(metauml_defaultFont, defaultscale);
  @#iFont.ignoreNegativeBase := 1;

  PictureInfo.@#iText  (2, 2, 2, 2)(@#iFont);
  PictureStackInfo.@#iStack (0, 0, 0, 0)(9)(@#iText);

  @#iStack.iPict.ignoreNegativeBase := 1;

  ShadeInfo.@#iShade;
  Margins.@#(2,2,2,2);

  @#foreColor   := .9white;
  @#borderColor := black;
  @#horizontalFolding := 10;
  @#verticalFolding := 10;
enddef;

vardef NoteInfoCopy@#(text src)=
  attributes(@#);
  var(color)   foreColor, borderColor;

  log "NoteInfoCopy: Copying usecase info";

  PictureStackInfoCopy.@#iStack (src.iStack);
  MarginsCopy.@#(src);
  ShadeInfoCopy.@#iShade(src.iShade);

  @#foreColor := src.foreColor;
  @#borderColor := src.borderColor;
  @#horizontalFolding := src.horizontalFolding;
  @#verticalFolding := src.verticalFolding;
enddef;

NoteInfo.iNote;

vardef Note@#(text contents)=
  ENote.@#(iNote)(contents);
enddef;

vardef ENote@#(text _info)(text contents)=
  ObjectEquations(@#);
  @#className := "Note";

  NoteInfoCopy.@#info(_info);

  numeric @#nLines; @#nLines := 0;
  string @#lines[];
  for l=contents:
    @#lines[@#nLines] := l;
    @#nLines := @#nLines + 1;
  endfor;

  EPictureStack.@#stack(@#info.iStack)(scantokens listArray(@#lines)(@#nLines))("vleftbase");
enddef;

vardef Note_layout@#=
  if @#layedout = 1:
    log "Note " & (str @#) & " has already been layed out";
  else:
    @#layedout := 1;
    log "Note layout: " & (str @#);

    PictureStack_layout.@#stack;

    @#width = @#stack.width + @#info.left + @#info.right + @#info.horizontalFolding;
    @#height = @#stack.height + @#info.top + @#info.bottom;

    @#top = @#stack.top + @#info.top;
    @#left = @#stack.left - @#info.left;
  fi;
enddef;

vardef Note_draw@#=
  Note_layout@#;
  objectEnsurePositioning.@#;

  attributes(@#);
  var(path) border, corner;

  @#border := @#nw -- (@#ne - (@#info.horizontalFolding, 0)) --
                      (@#ne - (0, @#info.verticalFolding)  ) -- @#se -- @#sw -- cycle;

  @#corner := (@#ne - (@#info.horizontalFolding, 0)) --
	     (@#ne - (@#info.horizontalFolding, @#info.verticalFolding)) --
             (@#ne - (0, @#info.verticalFolding));

  drawObjectShade(@#);

  fill Note_border.@# withcolor @#info.foreColor;
  draw Note_border.@# withcolor @#info.borderColor;

  draw @#corner withcolor @#info.borderColor;
  drawObject(@#stack);
enddef;

vardef Note_border@#=
  @#border
enddef;