summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/metauml/metauml_note.mp
blob: 083b686f65e368e72e572d819d936af0d321680a (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
138
139
140
% Copyright 2005 2015 Ovidiu Gheorghies
% Licensed under the Apache License, Version 2.0.

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;

% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost.
% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times, 
% but this macro makes sure that MetaPost won't try to load the file and display a message for that.
def inputonce text libraryFile=
	if not known scantokens ("_" & str libraryFile & "_mp"):
		%includeonce% show "Loading " & str libraryFile;
		scantokens ("input " & str libraryFile);
	else:
		%includeonce% show str libraryFile & " already loaded.";
	fi;
enddef;

inputonce metauml_defaults;
inputonce util_log;

inputonce util_object;
inputonce util_picture_stack;
inputonce util_shade;
inputonce 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);

  %% The following code cannot work when pictures are given in the contents argument, such as in:
  %% ENote.myNote(iNote)("This is a formula", TEX("$a=b$"));
  %%
  %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");

  EPictureStack.@#stack(@#info.iStack)(contents)("vleftbase");
enddef;

vardef Note_layout@#=
  if @#laidout = 1:
    log "Note " & (str @#) & " has already been layed out";
  else:
    @#laidout := 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;