blob: d611552b82f886757068921808f83ee7fb8a67b1 [file] [log] [blame]
nethercote5912c812004-02-15 15:38:08 +00001/* This file is part of hp2ps, a graph drawer for memory profiles.
2 Copyright (C) 2002 The University Court of the University of Glasgow.
3 This program is governed by the license contained in the file LICENSE. */
4
nethercotec9f36922004-02-14 16:40:02 +00005#include <stdio.h>
6#include <math.h>
7#include "Main.h"
8#include "Defines.h"
9#include "Dimensions.h"
10#include "HpFile.h"
11#include "Shade.h"
12
13/* own stuff */
14#include "Key.h"
15
16static void KeyEntry PROTO((floatish, char *, floatish));
17
18void Key()
19{
20 intish i;
21 floatish c;
22 floatish dc;
23
24 for (i = 0; i < nidents; i++) /* count identifiers */
25 ;
26
27 c = graphy0;
28 dc = graphheight / (floatish) (i + 1);
29
30 for (i = 0; i < nidents; i++) {
31 c += dc;
32 KeyEntry(c, identtable[i]->name, ShadeOf(identtable[i]->name));
33 }
34}
35
36
37
38static void
39KeyEntry(centreline, name, colour)
40 floatish centreline; char* name; floatish colour;
41{
42 floatish namebase;
43 floatish keyboxbase;
44 floatish kstart;
45
46 namebase = centreline - (floatish) (NORMAL_FONT / 2);
47 keyboxbase = centreline - ((floatish) KEY_BOX_WIDTH / 2.0);
48
49 kstart = graphx0 + graphwidth;
50
51 fprintf(psfp, "%f %f moveto\n", kstart + borderspace, keyboxbase);
52 fprintf(psfp, "0 %d rlineto\n", KEY_BOX_WIDTH);
53 fprintf(psfp, "%d 0 rlineto\n", KEY_BOX_WIDTH);
54 fprintf(psfp, "0 %d rlineto\n", -KEY_BOX_WIDTH);
55 fprintf(psfp, "closepath\n");
56
57 fprintf(psfp, "gsave\n");
58 SetPSColour(colour);
59 fprintf(psfp, "fill\n");
60 fprintf(psfp, "grestore\n");
61 fprintf(psfp, "stroke\n");
62
63 fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
64 fprintf(psfp, "%f %f moveto\n", kstart + (floatish) KEY_BOX_WIDTH + 2 * borderspace, namebase);
65
66 fprintf(psfp, "(%s) show\n", name);
67}