File: crwin.c

package info (click to toggle)
cgoban 1.9.14-18
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 3,448 kB
  • sloc: ansic: 36,037; sh: 707; makefile: 259
file content (98 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download | duplicates (9)
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
/*
 * src/crwin.c, part of Complete Goban (game program)
 * Copyright (C) 1995 William Shubert
 * See "configure.h.in" for more copyright information.
 */

#include <wms.h>
#include <but/but.h>
#include <but/text.h>
#include <but/tblock.h>
#include <but/box.h>
#include <but/timer.h>
#include "cgoban.h"
#include "msg.h"
#include "crwin.h"


/**********************************************************************
 * Forward declarations
 **********************************************************************/
static void  destroyed(But *but);
static ButOut  killCr(ButTimer *timer);


/**********************************************************************
 * Functions
 **********************************************************************/
Crwin  *crwin_create(Cgoban *cg, ButWin *win, int layer)  {
  Crwin  *cr;
  ButEnv  *env;
  int  x, y, w, h, textH;
  struct timeval  fiveSeconds;

  assert(MAGIC(cg));
  cr = wms_malloc(sizeof(Crwin));
  MAGIC_SET(cr);
  cr->env = env = cg->env;
  cr->box = butBoxFilled_create(win, layer, BUT_DRAWABLE);
  but_setPacket(cr->box, cr);
  but_setDestroyCallback(cr->box, destroyed);
  cr->title = butText_create(win, layer+1, BUT_DRAWABLE,
			     "CGoban " VERSION, butText_center);
  butText_setFont(cr->title, 2);
  cr->byBill = butTblock_create(win, layer+1, BUT_DRAWABLE,
				msg_byBillShubert, butText_center);
  cr->noWarr = butTblock_create(win, layer+1, BUT_DRAWABLE,
				msg_noWarranty, butText_center);
  cr->seeHelp = butTblock_create(win, layer+1, BUT_DRAWABLE,
				 msg_seeHelp, butText_center);

  textH = butEnv_fontH(env, 0);
  h = textH * 8;
  w = h * 2;
  x = (butWin_w(win) - w) / 2;
  y = (butWin_h(win) - h) / 3;
  but_resize(cr->box, x,y, w,h);
  butText_resize(cr->title, x + w/2, y += textH, textH);
  x += butEnv_stdBw(env) * 2;
  w -= butEnv_stdBw(env) * 4;
  y += textH;
  y += butTblock_resize(cr->byBill, x, y, w);
  y += butTblock_resize(cr->noWarr, x, y, w);
  butTblock_resize(cr->seeHelp, x, y, w);

  fiveSeconds.tv_usec = 0;
  fiveSeconds.tv_sec = 5;
  cr->timer = butTimer_create(cr, cr->box, fiveSeconds, fiveSeconds, FALSE,
			      killCr);

  return(cr);
}


static void  destroyed(But *but)  {
  Crwin  *cr = but_packet(but);

  assert(MAGIC(cr));
  MAGIC_UNSET(cr);
  wms_free(cr);
}


static ButOut  killCr(ButTimer *timer)  {
  Crwin  *cr = butTimer_packet(timer);

  assert(MAGIC(cr));
  butTimer_destroy(cr->timer);
  but_destroy(cr->title);
  but_destroy(cr->byBill);
  but_destroy(cr->noWarr);
  but_destroy(cr->seeHelp);
  /*
   * Kill the box last.  This is important, because killing the box
   *   triggers the destruction of the Crwin data structure.
   */
  but_destroy(cr->box);
  return(0);
}