AmendHub

Download

jcs

/

amend

/

commit_list.c

 

(View History)

jcs   *: Tweak font sizing, Geneva 11 isn't a standard size and looks bad Latest amendment: 89 on 2022-08-17

1 /*
2 * Copyright (c) 2021 joshua stein <jcs@jcs.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <string.h>
18 #include <stdio.h>
19 #include <time.h>
20 #include "browser.h"
21 #include "repo.h"
22 #include "util.h"
23
24 #define LIST_FONT geneva
25 #define LIST_FONT_SIZE 9
26
27 void amendment_list_draw_cell(ListHandle theList, Cell theCell,
28 short dataLen, Rect *cellRect, Boolean selected);
29
30 pascal void
31 amendment_list_ldef(short message, Boolean selected, Rect *cellRect,
32 Cell theCell, short dataOffset, short dataLen, ListHandle theList)
33 {
34 short id;
35
36 switch (message) {
37 case 0:
38 /* init */
39 break;
40 case 1:
41 /* update */
42 /* FALLTHROUGH */
43 case 2:
44 /* hilight */
45 amendment_list_draw_cell(theList, theCell, dataLen, cellRect,
46 selected);
47 break;
48 case 3:
49 /* close */
50 break;
51 }
52 }
53
54 void
55 amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen,
56 Rect *cellRect, Boolean selected)
57 {
58 RgnHandle savedClip;
59 PenState savedPenState;
60 GrafPtr savedPort;
61 Rect textRect;
62 char tmp[50];
63 struct repo_amendment *amendment = NULL;
64 struct tm *ttm = NULL;
65 short offset, len, height;
66
67 LGetCell(&amendment, &dataLen, theCell, theList);
68 if (amendment == NULL)
69 /* XXX: why does this happen? */
70 return;
71
72 textRect.left = cellRect->left;
73 textRect.right = cellRect->right;
74 textRect.top = cellRect->top;
75 textRect.bottom = cellRect->bottom + 1;
76 EraseRect(&textRect);
77 InsetRect(&textRect, 4, 4);
78
79 height = FontHeight(LIST_FONT, LIST_FONT_SIZE);
80 TextFace(bold);
81 TextFont(LIST_FONT);
82 TextSize(LIST_FONT_SIZE);
83 MoveTo(textRect.left, textRect.top + 6);
84
85 HLock(amendment->log);
86 for (len = 1; len < amendment->log_len; len++) {
87 if ((*(amendment->log))[len - 1] == '\r')
88 break;
89 }
90 DrawText(*(amendment->log), 0, len);
91 HUnlock(amendment->log);
92
93 ttm = localtime(&amendment->date);
94 snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d",
95 ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday,
96 ttm->tm_hour, ttm->tm_min, ttm->tm_sec);
97 MoveTo(textRect.left, textRect.top + height + 6);
98 TextFace(normal);
99 DrawText(tmp, 0, strlen(tmp));
100
101 MoveTo(textRect.left + 140, textRect.top + height + 6);
102 DrawText(amendment->author, 0, strlen(amendment->author));
103
104 snprintf(tmp, sizeof(tmp), "%d (+), %d (-)",
105 amendment->adds, amendment->subs);
106 MoveTo(textRect.left + 220, textRect.top + height + 6);
107 DrawText(tmp, 0, strlen(tmp));
108
109 if (selected)
110 InvertRect(cellRect);
111 }