DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2539
Version: 1.3-current
Attached file "kitchentimer.cpp"...
Link: http://www.fltk.org/str.php?L2539
Version: 1.3-current
/*===============================================================================
Program Name: kitchentimer
Abstract: kitchen timer/stopwatch
Requirement(s): None
Return Value(s): None
Author(s): Jim Michaels <[email protected]>
Copyright 2007 Jim Michaels
This file is part of timer.
kitchentimer 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 3 of the License, or
(at your option) any later version.
kitchentimer 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 phone. If not, see <http://www.gnu.org/licenses/>.
===============================================================================
*/
#define PROGRAM_VERSION "2.0"
#include <process.h>
//#include <stdlib.h>
#include <FL/Fl.h>
#include <FL/Fl_Window.h>
#include <FL/Fl_Button.h>
#include <FL/Fl_Check_Button.h>
#include <FL/Fl_Tooltip.h>
#include <FL/Fl_Text_Display.h>
#include <FL/Fl_Input.h>
#include <FL/Fl_Output.h>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <string>
#include <string.h>
#include <stdio.h>
#include <tr1/stdint.h>
class CMessageBox : public Fl_Window {
static void OnOK(Fl_Widget *w, void *userdata) {
~CMessageBox();
}
private:
Fl_Button *msgButton;
Fl_Text_Display *td;
public:
Fl_Window *msgWindow;
CMessageBox(char * wintitle, char * msg) {
msgWindow = new Fl_Window(141, 158, 326, 98, wintitle);
td = new Fl_Text_Display(5, 5, 315, 55);
td->value(msg);
msgWindow->add(td);
msgButton = new Fl_Button(120, 35, 70, 25, "&OK");
msgButton->callback(OnOK);
msgWindow->add(msgButton);
msgWindow->set_modal();
show();
}
~CMessageBox() {
msgWindow->~Fl_Window();
}
}
/*
class CHelpBox : public Fl_Window {
static void OnOK(Fl_Widget *w, void *userdata) {
~CMessageBox();
}
private:
Fl_Window *msgWindow;
FL_Button *msgButton;
FL_Text_Display *msgTextDisplay;
public:
CHelpBox(int w, int h, const char *name=0) {
string scaption("KitchenTimer v");
scaption += PROGRAM_VERSION;
scaption += " - Help";
msgWindow = new Fl_Window(128, 221, 326, 98, scaption.c_str);
msgWindow->modal();
msgTextDisplay = new Fl_Text_Display(5, 5, 530, 325);
msgTextDisplay->buffer(
"'Command to Execute' should be a full path or be in the PATH
environment variable.\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
"\r\n"
);
msgButton = new Fl_Button(120, 35, 70, 25, "&OK");
msgButton->callback(OnOK);
msgTextDisplay = new Fl_Text_Display(
show();
}
~CHelpBox() {
msgWindow->~Fl_Window();
}
}
*/
class CKitchenTimerUI : public Fl_window {
// static void OnQuit(Fl_Widget *w, void *userdata) {
// }
static void OnBTNStartCountUp(Fl_Widget *w, void *userdata) {
starttime=gettime();
countby=1;
}
static void OnBTNStartCountDown(Fl_Widget *w, void *userdata) {
int64_t temptimediff=stringtoDTIME(TEXTin->value()) //temporary
variable
if (0==temptimediff) {
msgboxoops = new CMessageBox("kitchentimer input error", "the
input must be in the format '15 days 23:59:59.999'");
TEXTin->value("0 days 00:00:00.000");
} else {
starttime=gettime()+temptimediff;
countby=-1;
}
}
static void OnBTNStop(Fl_Widget *w, void *userdata) {
countby=0;
difftime=curtime-starttime;
}
static void OnBTNReset(Fl_Widget *w, void *userdata) {
countby=0;
starttime=0;
difftime=0;
TEXTout->value("");
}
static void OnBTNDown(Fl_Widget *w, void *userdata) {
countby=-1;
starttime=gettime()+stringtoDTIME(TEXTin->value())+difftime;
curtime=gettime();
}
static void OnBTNUp(Fl_Widget *w, void *userdata) {
countby=1;
starttime=gettime()-difftime;
curtime=gettime();
}
// static void OnQuit(Fl_Widget *w, void *userdata) {
// }
public:
int countby; //-1:countdown, 1:countup, 0:don't count
int starttime;
int curtime;
int difftime;
int execDone = 0;
Fl_Window *window;
Fl_Button *BTNStartCountUp;
Fl_Button *BTNUp;
Fl_Button *BTNStop;
Fl_Button *BTNReset;
Fl_Button *BTNDown;
Fl_Button *BTNStartCountDown;
FL_Input *TEXTin;
FL_Input *TEXTcmd;
FL_Output *TEXTout;
Fl_Timer *timer;
Fl_Check_Button *CHKbeep;
Fl_Check_Button *CHKexec;
CMessageBox * msgboxoops;
CMessageBox * msgboxtimesup;
//CHelpBox * helpbox;
CKitchenTimerUI() {
countby=starttime=curtime=execdone=0;
difftime=curtime-starttime;
string scaption("KitchenTimer v");
scaption += PROGRAM_VERSION;
window = new Fl_Window(9, 30, 628, 171, scaption.c_str);
TEXTin = new Fl_Input(300, 10, 325, 25, "countdown time (format: 0
days 00:00:00.000)");
TEXTin->value("0 days 00:00:00.000");
TEXTin->tooltip("format is '9999999 days 23:59:59.999' no maximum
on number of days.");
window->add(TEXTin);
TEXTout = Fl_Output(300, 40, 325, 25, "Elapsed Time");
TEXTout->tooltip("elapsed time or time counter");
window->add(TEXTout);
BTNStartCountUp = new Fl_Button(5, 70, 180, 25, "Reset and Start
Count U&p")
BTNStartCountUp->callback(OnBTNStartCountUp);
window->add(BTNStartCountUp);
BTNUp = new Fl_Button(190, 70, 50, 25, "&Up")
BTNUp->callback(OnBTNUp);
window->add(BTNUp);
BTNStop = new Fl_Button(250, 70, 45, 25, "&Stop")
BTNStop->callback(OnBTNStop);
window->add(BTNStop);
BTNReset = new Fl_Button(305, 70, 55, 25, "&Reset")
BTNReset->callback(OnBTNReset);
window->add(BTNReset);
BTNDown = new Fl_Button(370, 70, 50, 25, "&Down")
BTNDown->callback(OnBTNDown);
window->add(BTNDown);
BTNStartCountDown = new Fl_Button(430, 70, 195, 25, "Reset and
Start Count Dow&n");
BTNStartCountDown->callback(OnBTNStartCountDown);
window->add(BTNStartCountDown);
CHKbeep = new Fl_Check_Button(85, 100, 25, 25, "Turn on countdown
alarm");
CHKbeep->tooltip("turns on repeating beep alarm when checked.
alarm stops with the stop button.");
CHKbeep->value(1);//checked
window->add(CHKbeep);
CHKexec = new Fl_Check_Button(285, 100, 25, 25, "execute command on
countdown alarm");
CHKexec->tooltip("turns on repeating beep alarm when checked.
alarm stops with the stop button.");
//CHKexec->value(1);
window->add(CHKexec);
TEXTcmd = new Fl_Input(155, 130, 470, 25, "&Command to execute");
TEXTcmd->value("Notepad.exe");
TEXTcmd->tooltip("command should be a full path or be in the PATH");
window->add(TEXTcmd);
//start timer
timer = new Fl_Timer(FL_HIDDEN_TIMER, 0, 0, 1, 1);
timer->direction(0);//count up
timer->callback(OnTimer);
window->add(timer);
window->end();
//start window
show();
//callback(OnQuit);
}
//string getInputValue() { return string(TEXTin->value()); }
bool isbeep() { return 0 != CHKbeep->value(); }
bool isexec() { return 0 != CHKexec->value(); }
void Run() {
while (window->shown()) {
//the following code is executed in a "while forever" windows
message loop.
//as long as messages are being processed, this will execute.
if (0 != countby) {
TEXTout->value(elapsedtime().c_str());
//now handle the alarm...
//if counting down and time difference passed 0 into
negative, ...
if (-1 == countby && curtime >= starttime) {
if (isexec() && !execdone) {
system(TEXTcmd->value()); //execute system command
execdone=true; //make sure it's done only once.
}
if (isbeep()) {
//make repeated noise at regular intervals.
if (gettime() % 2*400 >=400
&& gettime() % 8*2*400 >= 4*400) {
Beep(880,150); // sound frequency,ms
}
} else {
//display a messagebox instead and don't do
anything special. it already makes a noise.
msgboxtimesup = new
CMessageBox("KitchenTimer","Times up!");
window->add(msgboxtimesup->msgWindow);
countby=0;
}
}
}//if 0 != countby
fltk::wait(0);//waste no time! But process window messages.
}//while
}//Run()
}
//func timediff()
// curtime = gettime()
// return curtime - starttime
//}
//---------------------------------------------------------------------------
//gregorian-julian calendar conversion routines. do not use with
//gregorian dates under 1500AD. cerain events occurred which interrupted
//the calendar.
//algorithm from http://en.wikipedia.org/wiki/Julian_day
//Author: Jim Michaels <[email protected]>
//Abstract: func library for conversion and time extraction from Julian and
// Gregorian Dates and Javascript Date() objects.
//Create Date: , 2008
//Current Date: Oct 24, 2009
//Version 2.2
//If you want to do Gregorian date differences based on Julian date differences,
// make sure you add 4713 to the year component. e.g.
// $y=GregorianY($jdiff)+4713//
// everything else is normal.
//Copyright 2008,2009 Jim Michaels
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
double curtimeToJDN() {
SYSTEMTIME tCur;
GetSystemTime(&tCur);
return GregorianToJulian(tcur.wYear, tCur.wMonth, tCur.wDay, tCur.wHour,
tCur.wMinute, tCur.wSecond, tCur.wMilliseconds);
}
int64_t curtimeToDTIME() {
SYSTEMTIME tCur;
GetSystemTime(&tCur);
return numstoDTIME(tcur.wYear*12*31+(tCur.wMonth-1)*31+tCur.wDay-1,
tCur.wHour, tCur.wMinute, tCur.wSecond, tCur.wMilliseconds);
}
double fdiv(double a, double b) {
return a/b;
}
double epoch=GregorianToJulian(0,0,0,0,0,0,0);
// epoch is julian(-4713,11,24,12,0,0)// hours are 0..23, months are 1..12,
days are 1..31, years start with -4713.
double GregorianToJulian(int Y,int Mo,int D,int H,int Mi,int S,int ms) {
double a=floor((14-Mo)/12);
double y=Y+4800-a;
double m=Mo+(12*a)-3;
return D + floor((153*m+2)/5) + (365*y) + floor(y/4) - floor(y/100) +
floor(y/400) - 32045 + ((H-12)/24) + (Mi/1440) + (S/86400) + (ms/86400000);
}
//func JulianFromDate(date) {
// $a=floor((14-(date.getMonth()+1))/12);
// $y=date.getFullYear()+4800-$a;
// $m=(date.getMonth()+1)+(12*$a)-3;
// return date.getDate() + floor((153*$m+2)/5) + (365*$y) + floor($y/4) -
floor($y/100) + floor($y/400) - 32045 + ((date.getHours()-12)/24) +
(date.getMinutes()/1440) + (date.getSeconds()/86400) +
(date.getMilliseconds()/86400000);
//}
//func DateToJulian(date) {
// $a=floor((14-(date.getMonth()+1))/12);
// $y=date.getFullYear()+4800-$a;
// $m=(date.getMonth()+1)+(12*$a)-3;
// return date.getDate() + floor((153*$m+2)/5) + (365*$y) + floor($y/4) -
floor($y/100) + floor($y/400) - 32045 + ((date.getHours()-12)/24) +
(date.getMinutes()/1440) + (date.getSeconds()/86400) +
(date.getMilliseconds()/86400000);
//}
//func to2DigitString($n) {
// $s=n.toString();
// if (StringLen(s)=1) {
// string ss("0");
// ss += s;
// }
// return ss;
//}
//func JulianToDate($JDN)
// Dim $J = $JDN+0.5// //shifts epoch 1/2 day
// Dim $j = $J + 32044// //shifts epoch back to astronomical year -4800
// Dim $g = fdiv($j , 146097)//
// Dim $dg = fmod($j , 146097)//
// Dim $c = fdiv((fdiv($dg , 36524) + 1) * 3 , 4)//
// Dim $dc = $dg - ($c * 36524)//
// Dim $b = fdiv($dc , 1461)//
// Dim $db = fmod($dc , 1461)//
// Dim $a = fdiv((fdiv($db , 365) + 1) * 3 , 4)//
// Dim $da = $db - ($a * 365)//
// Dim $y = ($g * 400) + ($c * 100) + ($b * 4) + $a// //integer number of
full years elapsed since March 1, 4801 BC at 00:00 UTC
// Dim $m = fdiv(($da * 5 + 308) , 153) - 2// //integer number of full
months elapsed since the last March 1 at 00:00 UTC
// Dim $d = $da - fdiv(($m + 4) * 153 , 5) + 122// //number of days
elapsed since day 1 of the month at 00:00 UTC, including fractions of one day
// Dim $Y = $y - 4800 + fdiv(($m + 2), 12)//
// Dim $Mo = fmod(($m + 2) , 12) + 1//
// Dim $D = $d + 1//
// Dim $t=$J-floor($J)//
// Dim $HH=fmod(24*$t+12, 24)//
// $t=fdiv(24*$t+12, 24)//
// Dim $MM=fmod(60*$t, 60)//
// $t=fdiv(60*$t, 60)//
// Dim $SS=fmod(60*$t, 60)//
// $t=fdiv(60*$t, 60)//
// Dim $MS=fmod(1000*$t, 1000)//
// $t=fdiv(1000*$t, 1000)//
//
// Dim $date=new Date($Y, $Mo-1, $D, $HH, $MM, $SS, $MS)//
//
// return $date//
//}
//func DateFromJulian($JDN)
// Dim $J = $JDN+0.5//
// Dim $j = $J + 32044//
// Dim $g = fdiv($j , 146097)//
// Dim $dg = fmod($j , 146097)//
// Dim $c = fdiv((fdiv($dg , 36524) + 1) * 3 , 4)//
// Dim $dc = $dg - ($c * 36524)//
// Dim $b = fdiv($dc , 1461)//
// Dim $db = fmod($dc , 1461)//
// Dim $a = fdiv((fdiv($db , 365) + 1) * 3 , 4)//
// Dim $da = $db - ($a * 365)//
// Dim $y = ($g * 400) + ($c * 100) + ($b * 4) + $a//
// Dim $m = fdiv(($da * 5 + 308) , 153) - 2//
// Dim $d = $da - fdiv(($m + 4) * 153 , 5) + 122//
// Dim $Y = $y - 4800 + fdiv(($m + 2), 12)//
// Dim $Mo = fmod(($m + 2) , 12) + 1//
// Dim $D = $d + 1//
// Dim $t=$J-floor($J)//
// Dim $HH=fmod(24*$t+12, 24)//
// $t=fdiv(24*$t+12, 24)//
// Dim $MM=fmod(60*$t, 60)//
// $t=fdiv(60*$t, 60)//
// Dim $SS=fmod(60*$t, 60)//
// $t=fdiv(60*$t, 60)//
// Dim $MS=fmod(1000*$t, 1000)//
// $t=fdiv(1000*$t, 1000)//
//
// Dim $date=new Date($Y, $Mo-1, $D, $HH, $MM, $SS, $MS)//
//
// return $date//
//}
string GregorianStringFromJulian(double JDN) {
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double t=J-floor(J);
double HH=fmod(24*t+12, 24);
t=fdiv(24*t+12, 24);
double MM=fmod(60*t, 60);
t=fdiv(60*t, 60);
double SS=fmod(60*t, 60);
t=fdiv(60*t, 60);
double MS=fmod(1000*t, 1000);
t=fdiv(1000*t, 1000);
return StringFormat("%d/%d/%d %02d:%02d:%02d.%03d",Mo-1, D, Y, HH, MM,
SS, MS)
}
int JulianToGregorianY(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return Y;
}
int JulianToGregorianMo(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return Mo;
}
int JulianToGregorianD(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return floor(D);
}
int JulianToGregorianH(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return floor(H);
}
int JulianToGregorianMi(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return floor(Mi);
}
int JulianToGregorianS(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return floor(S);
}
int JulianToGregorianMs(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double Ms = (S - floor(S))*1000;
return floor(Ms);
}
double JulianToGregorianFracSec(double JDN)
double J = JDN+0.5;
double j = J + 32044;
double g = fdiv(j , 146097);
double dg = fmod(j , 146097);
double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
double dc = dg - (c * 36524);
double b = fdiv(dc , 1461);
double db = fmod(dc , 1461);
double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
double da = db - (a * 365);
double y = (g * 400) + (c * 100) + (b * 4) + a;
double m = fdiv((da * 5 + 308) , 153) - 2;
double d = da - fdiv((m + 4) * 153 , 5) + 122;
double Y = y - 4800 + fdiv((m + 2), 12);
double Mo = fmod((m + 2) , 12) + 1;
double D = d + 1;
double H = (d - floor(d))*24;
double Mi= (H - floor(H))*60;
double S= (Mi - floor(Mi))*60;
double fracSec = S - floor(S);
return fracSec;
}
int64_t numstoDTIME(int64_t days, int H, int M, int S, int MS) {
return MS + S*1000 + M*1000*60 + H*1000*60*60 + days*1000*60*60*24;
}
string numstoDTIMEstring(int64_t days, int H, int M, int S, int MS) {
char s[1000];
sprintf(s, "%I64d days %02d:%02d:%02d.%03d", days, H, M, S, MS);
return string(s);
}
string DTIMEtostring(int64_t dtime) {
int ms=DTIMEtoMS($dtime);
int s=DTIMEtoS($dtime);
int m=DTIMEtoM($dtime);
int h=DTIMEtoH($dtime);
int64_t days=DTIMEtodays($dtime);
char s[1000];
sprintf(s, "%I64d days %02d:%02d:%02d.%03d", abs($days), abs($h), abs($m),
abs($s), abs($ms));
return string(s);
}
int64_t stringtoDTIME(string dtimestr) {
string sdays(" days ");
int sldays=sdays.length();
int idays=dtimestr.find(sdays);
int firstcolon=dtimestr.find(":");
int lastcolon=dtimestr.find(":",firstcolon+1);
int dot=dtimestr.find(".");
if (0==lastcolon
|| 0==firstcolon
|| 0==idays) {
return 0;
}
int64_t days = _atoi64(dtimestr.substr(0,idays).c_str());
int ms = _atoi64(dtimestr.substr(dot+1).c_str());
int seconds =
_atoi64(dtimestr.substr(lastcolon+1,1+dot-(lastcolon+1)));
int minutes =
_atoi64(dtimestr.substr(firstcolon+1,1+lastcolon-(firstcolon+1)).c_str());
int hours =
_atoi64(dtimestr.substr(idays+sldays,1+firstcolon-(idays+sldays)).c_str());
//$t=numstoDTIME($days, $hours, $minutes, $seconds, $ms)
//msgbox(0,$t,$days&"days"&$hours&"hours"&$minutes&"minutes"&$seconds&"seconds"&$ms&"ms")
return numstoDTIME(days, hours, minutes, seconds, $ms);
}
int DTIMEtoMS(int64_t dtime) {
return dtime % 1000;
}
int DTIMEtoS(int64_t dtime) {
return int64_t(dtime/1000) % 60;
}
int DTIMEtoM(int64_t dtime) {
return int64_t(dtime/(1000*60)) % 60;
}
int DTIMEtoH(int64_t dtime) {
return int64_t (dtime/(1000*60*60)) % 24;
}
int64_t DTIMEtodays(int64_t dtime) {
return int64_t(dtime/(1000*60*60*24));
}
//---------------------------------------------------------------------------
int64_t gettime() {
return curtimeToDTIME()
}
string stringtotimediff(string s) {
string sdays(" days ");
int sldays=sdays.length();
int idays=s.find(sdays);
int firstcolon=s.find(":");
int lastcolon=s.find(":",firstcolon+1);
int dot=s.find(".");
if (0==lastcolon
|| 0==firstcolon
|| 0==idays) {
return string("0 days 00:00:00.000");
}
int64_t days = _atoi64(s.substr(1,idays).c_str());
int ms = _atoi64($s.substr(dot+1).c_str());
int seconds =
_atoi64($s.substr(lastcolon+1,1+dot-(lastcolon+1)).c_str());
int minutes =
_atoi64($s.substr(firstcolon+1,1+lastcolon-(firstcolon+1)).c_str());
int hours =
_atoi64($s.substr(idays+sldays,1+firstcolon-(idays+sldays)).c_str());
//msgbox(0,$t,$days&"days"&$hours&"hours"&$minutes&"minutes"&$seconds&"seconds"&$ms&"ms")
return numstoDTIMEstring(days, hours, minutes, seconds, ms);
}
string elapsedtime() {
//msgbox(0,"",starttime)
curtime = gettime();
//msgbox(0,"gettime",curtime)
int64_t diff=curtime - starttime;
int64_t absdiff=($diff);
return DTIMEtostring($absdiff)
}
int main(int argc, char * argv[]) {
argc--;argv++;
if (argc >= 1) {
if (
0==_stricmp(argv[0],"--version")||
0==_stricmp(argv[0],"--ver")||
0==_stricmp(argv[0],"--v")||
0==_stricmp(argv[0],"-version")||
0==_stricmp(argv[0],"-ver")||
0==_stricmp(argv[0],"-v")||
0==_stricmp(argv[0],"/help")||
0==_stricmp(argv[0],"/ver")||
0==_stricmp(argv[0],"/v")
) {
printf("Version %s\n", PROGRAM_VERSION);
return 0;
} else if (
0==_stricmp(argv[0],"--help")||
0==_stricmp(argv[0],"--h")||
0==_stricmp(argv[0],"--?")||
0==_stricmp(argv[0],"-help")||
0==_stricmp(argv[0],"-h")||
0==_stricmp(argv[0],"-?")||
0==_stricmp(argv[0],"/help")||
0==_stricmp(argv[0],"/h")||
0==_stricmp(argv[0],"/?")
) {
help();
return 0;
} else {
printf("ERROR: invalid switch '%s'\n", arg[0]);
help();
return 1;
}
}
KitchenTimerUI ktui();
ktui.run();
// Run the GUI until the dialog is closed
while (Fl::wait()) {
}
return 0;
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs