nethercote | 5912c81 | 2004-02-15 15:38:08 +0000 | [diff] [blame] | 1 | /* 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 | |
nethercote | c9f3692 | 2004-02-14 16:40:02 +0000 | [diff] [blame] | 5 | #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 | |
| 16 | static void KeyEntry PROTO((floatish, char *, floatish)); |
| 17 | |
| 18 | void 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 | |
| 38 | static void |
| 39 | KeyEntry(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 | } |