File: clock.h

package info (click to toggle)
eboard 0.9.5-6.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,968 kB
  • ctags: 2,641
  • sloc: cpp: 23,116; perl: 909; sh: 104; makefile: 65
file content (150 lines) | stat: -rw-r--r-- 3,554 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
/* $Id: clock.h,v 1.11 2003/06/29 03:17:16 bergo Exp $ */

/*

    eboard - chess client
    http://eboard.sourceforge.net
    Copyright (C) 2000-2003 Felipe Paulo Guazzi Bergo
    bergo@seul.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#ifndef CLOCK_H
#define CLOCK_H 1

#include <sys/time.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <time.h>

#include "stl.h"
#include "eboard.h"
#include "widgetproxy.h"

class ClockHost {
 public:
  virtual void updateClock()=0;
};

// values for getActive()
#define CLK_WHITE_STOPPED -2
#define CLK_WHITE_RUNNING -1
#define CLK_STOPPED        0
#define CLK_BLACK_RUNNING  1
#define CLK_BLACK_STOPPED  2

class ChessClock : public UpdateInterface {
 public:
  ChessClock();
  virtual ~ChessClock();

  void setClock(int whitesec,int blacksec,int activep,int countdown);
  void setHost(ClockHost *hostp);
  void setAnotherHost(ClockHost *hostp);
  void setMirror(ChessClock *dest);

  int  getActive();
  int  getValue(int black);

  // which= -1=white 0=active one 1=black
  void incrementClock(int which, int secs);

  bool lowTimeWarning(piece mycolor);

  void update();
  
  int id;  

 private:
  int value[2],val_ref[2];
  time_t t_ref[2];
  int active;
  int countdownf;
  ClockHost *host, *host2;
  ChessClock *mirror;
  struct timeval LastWarning;

  static int freeid;
};


gint clockmaster_timeout(gpointer data);

class ClockMaster {
 public:
  ClockMaster();
  void append(ChessClock *clockp);
  void remove(ChessClock *clockp);

 private:
  void update();

  list<ChessClock *> clocks;
  int timeout_on;
  int timeout_id;

  friend gint clockmaster_timeout(gpointer data);
};

#define TCF_GNUCHESS4QUIRK  0x01

class TimeControl {
 public:  
  TimeControl();
  TimeControl &operator=(TimeControl &src);
  int          operator==(TimeControl &src);
  int          operator!=(TimeControl &src);

  void fromSerialization(const char *s);

  static void secondsToString(char *dest, int secs, bool units=false);
  static int  stringToSeconds(char *src);

  void setSecondsPerMove(int seconds);
  void setIcs(int base /* secs */, int increment /* secs */);
  void setXMoves(int nmoves, int nsecs);

  bool isRegressive();
  int  startValue();

  void toXBoard(char *dest, int flags = 0);
  void toString(char *dest);

  TimeControlMode mode;
  int value[2];
};

void tced_ok(GtkWidget *w, gpointer data);
void tced_dropmenu(GtkMenuItem *w, gpointer data);

class TimeControlEditDialog : public ModalDialog {
 public:
  TimeControlEditDialog(TimeControl *tc, bool allownone=true);
  virtual ~TimeControlEditDialog() {}
  void setUpdateListener(UpdateInterface *ui);

 private:
  GtkWidget *mi[4], *e[5], *f[3];
  TimeControl     *src;  
  TimeControl     local;
  UpdateInterface *listener;

  friend void tced_ok(GtkWidget *w, gpointer data);
  friend void tced_dropmenu(GtkMenuItem *w, gpointer data);
};

#endif