-
Notifications
You must be signed in to change notification settings - Fork 0
/
bittime.m
executable file
·306 lines (238 loc) · 5.54 KB
/
bittime.m
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
BitTime
(c)2008 KR & con3 Office
*/
#import "bittime.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSSound.h"
@implementation bittime
//初期化
- (id)init {
self = [super init];
if (!self) {
return nil;
}
return self;
}
//ウインドウを閉じて終了
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}
//終了処理
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
if([alarm_au isPlaying] == YES){
[alarm_au stop];
}
if (timer_working){
[mytimer invalidate];
}
}
//終了
- (void)dealloc
{
[alarm_au release];
[mytimer release];
[ss release];
[mm release];
[super dealloc];
}
//アプリ初期化
- (void)awakeFromNib
{
timer_working = FALSE;
botan = FALSE;
mm = [[NSMutableString alloc] init];
ss = [[NSMutableString alloc] init];
alarm_au = [NSSound soundNamed:@"alarm"];
[mm setString:@"00"];
[ss setString:@"00"];
//初期化
/*
NSLog(@"Min:%@, Sec:%@",mm,ss);
[min setStringValue:@"00"];
[sec setStringValue:@"00"];
NSDate* nowTime = [NSDate date];
[mm setString:[nowTime descriptionWithCalendarFormat:@"%M" timeZone:nil locale:nil]];
[ss setString:[nowTime descriptionWithCalendarFormat:@"%S" timeZone:nil locale:nil]];
*/
}
//時間設定(総秒数からの正規化及び,表示と変数の動機)
- (void)set_time:(int)now_second
{
int tmp_second;
int tmp_min;
int tmp_sec;
if (now_second > 5999) {
tmp_second = 5999; //ルーチン内数値修正
now_sec = 5999; //カウント用変数修正
total_sec = 5999; //設定総秒数修正
}
else{
tmp_second = now_second;
}
tmp_min = tmp_second / 60;
tmp_sec = tmp_second - (tmp_min * 60);
[mm setString:[NSString stringWithFormat:@"%02d",tmp_min]];
[ss setString:[NSString stringWithFormat:@"%02d",tmp_sec]];
[min setStringValue:[NSString stringWithFormat:@"%02d",tmp_min]];
[sec setStringValue:[NSString stringWithFormat:@"%02d",tmp_sec]];
[test setString:[NSString stringWithFormat:@"%02d",tmp_sec]];
[test sizeToFit];
}
//数値入力処理(秒数分数間の数字繰り上がり処理と表示)
- (void)input_num:(NSString*)in_num
{
NSMutableString* oldm;
NSMutableString* olds;
oldm = [[NSMutableString alloc] init];
olds = [[NSMutableString alloc] init];
[oldm setString:mm];
[olds setString:ss];
NSRange leftone = NSMakeRange(0,1); //左の1文字分(3文字前提)
NSRange righttwo = NSMakeRange(1,2); //右の2文字分(3文字前提)
[mm setString:[[oldm stringByAppendingString:[olds substringWithRange:leftone]] substringWithRange:righttwo]];
[ss setString:[[olds stringByAppendingString:in_num] substringWithRange:righttwo]];
//表示用文字列での数値繰り上がり処理
m = [mm intValue];
s = [ss intValue];
//数値への変換と総秒数計算
[min setStringValue:[NSString stringWithFormat:@"%02d",m]];
[sec setStringValue:[NSString stringWithFormat:@"%02d",s]];
//表示
}
//カウントダウン処理(ループから呼び出し)
- (void)count_down
{
now_sec--;
if (now_sec)
{
[self set_time:now_sec];
//NSLog(@"Now:%d",now_sec);
return;
}
[self set_time:now_sec];
//NSLog(@"Now:%d",now_sec);
[mytimer invalidate];
timer_working = FALSE;
//タイマー解除
[mm setString:@"00"];
[ss setString:@"00"];
m = [mm intValue];
s = [ss intValue];
total_sec = (m * 60) + s;
//リセット
[alarm_au play];
//アラーム音再生
[SSbutton setState:NSOffState]; //「Start」表示
}
//数字ボタン
- (IBAction)b0:(id)sender
{
if (!timer_working){
[self input_num:@"0"];
}
}
- (IBAction)b1:(id)sender
{
if (!timer_working){
[self input_num:@"1"];
}
}
- (IBAction)b2:(id)sender
{
if (!timer_working){
[self input_num:@"2"];
}
}
- (IBAction)b3:(id)sender
{
if (!timer_working){
[self input_num:@"3"];
}
}
- (IBAction)b4:(id)sender
{
if (!timer_working){
[self input_num:@"4"];
}
}
- (IBAction)b5:(id)sender
{
if (!timer_working){
[self input_num:@"5"];
}
}
- (IBAction)b6:(id)sender
{
if (!timer_working){
[self input_num:@"6"];
}
}
- (IBAction)b7:(id)sender
{
if (!timer_working){
[self input_num:@"7"];
}
}
- (IBAction)b8:(id)sender
{
if (!timer_working){
[self input_num:@"8"];
}
}
- (IBAction)b9:(id)sender
{
if (!timer_working){
[self input_num:@"9"];
}
}
//スタートストップボタン
- (IBAction)bSS:(id)sender
{
total_sec = ([mm intValue] * 60) + [ss intValue];
//総秒数計算
if(!botan){
botan = TRUE;
SSbutton = sender; //トグルボタンのインスタンス先を保存
}
if(!total_sec){
[sender setState:NSOffState]; //「Start」表示
timer_working = FALSE;
if([alarm_au isPlaying] == YES){
[alarm_au stop];
}
return; //0秒の場合は反応せず返す
}
if (!timer_working){
[sender setState:NSOnState]; //「Stop」表示
now_sec = total_sec; //カウント用秒数変数にコピー
[self set_time:now_sec];
mytimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(count_down) userInfo:nil repeats:YES];
timer_working = TRUE;
//タイマー稼働
return;
}
[sender setState:NSOffState];
//「Start」表示
[mytimer invalidate];
timer_working = FALSE;
//タイマー解除
total_sec = now_sec;
m = [mm intValue];
s = [ss intValue];
//途中で止めた場合の現在数値を設定
}
//メニュー「File->New」
- (IBAction)new:(id)sender
{
[mm setString:@"00"];
[ss setString:@"00"];
m = [mm intValue];
s = [ss intValue];
total_sec = (m * 60 ) + s;
[self set_time:total_sec];
//リセット
}
@end