#ifndef lint
#endif /* lint */
/***********************************************************
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <time.h>
#include <X11/StringDefs.h>
#include <X11/IntrinsicP.h>
#include <./Xaw3_1XawInit.h>
#include <./Xaw3_1ClockP.h>
extern long time();
static void erase_hands();
static round();
/* Private Definitions */
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? -(a) : (a))
/* Initialization of defaults */
};
static void ClassInitialize();
{ /* core fields */
/* superclass */ &widgetClassRec,
/* class_name */ "Clock",
/* widget_size */ sizeof(ClockRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* xrm_class */ NULL,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
}
};
/****************************************************************
*
* Private Procedures
*
****************************************************************/
static void ClassInitialize()
{
NULL, 0 );
}
/* ARGSUSED */
{
else
char *str;
long time_value;
(void) time(&time_value);
DefaultGCOfScreen(XtScreen(w))) );
}
else
myXGCV.line_width = 0;
w->clock.interval_id = 0;
}
{
#ifdef notdef
*valueMask |= CWBitGravity;
#endif
switch (w->clock.backing_store) {
case Always:
case NotUseful:
case WhenMapped:
break;
}
}
{
}
{
/* don't do this computation if window hasn't been realized yet. */
/* need signed value since Dimension is unsigned */
}
}
/* ARGSUSED */
{
erase_hands (w, (struct tm *) 0);
DrawClockFace(w);
} else {
}
}
/* ARGSUSED */
{
long time_value;
char *time_ptr;
w->clock.interval_id =
(void) time(&time_value);
/*
* Beep on the half hour; double-beep on the hour.
*/
}
}
int clear_from;
/*
* Clear any left over bits
*/
} else {
/*
* The second (or minute) hand is sec (or min)
* sixtieths around the clock face. The hour hand is
* (hour + min/60) twelfths of the way around the
* clock-face. The derivation is left as an excercise
* for the reader.
*/
/*
* 12 hour clock.
*/
erase_hands (w, &tm);
/*
* Calculate the hour hand, fill it in with its
* color and then outline it. Next, do the same
* with the minute hand. This is a cheap hidden
* line algorithm.
*/
DrawHand(w,
);
);
DrawHand(w,
);
);
}
}
DrawSecond(w,
);
);
);
}
}
}
ClockWidget w;
{
/*
* Erase old hands.
*/
);
}
}
{
}
}
}
}
/*
* DrawLine - Draws a line.
*
* blank_length is the distance from the center which the line begins.
* length is the maximum length of the hand.
* Fraction_of_a_circle is a fraction between 0 and 1 (inclusive) indicating
* how far around the circle (clockwise) from high noon.
***** Note: in this routine, fraction_of_a_circle is actually the minute
***** tic we are drawing, 0 through 59. This is due to a Solaris 2.0
***** compiler bug I was not able to work around any other way. C'est la vie.
*
*
* The blank_length feature is because I wanted to draw tick-marks around the
* circle (for seconds). The obvious means of drawing lines from the center
* to the perimeter, then erasing all but the outside most pixels doesn't
* work because of round-off error (sigh).
*/
ClockWidget w;
int fraction_of_a_circle;
{
double cos();
double sin();
/*
* A full circle is 2 PI radians.
* Angles are measured from 12 o'clock, clockwise increasing.
* Since in X, +x is to the right and +y is downward:
*
* x = x0 + r * sin(theta)
* y = y0 - r * cos(theta)
*
*/
/* break this out so that stupid compilers can cope */
}
/*
* DrawHand - Draws a hand.
*
* length is the maximum length of the hand.
* width is the half-width of the hand.
* Fraction_of_a_circle is a fraction between 0 and 1 (inclusive) indicating
* how far around the circle (clockwise) from high noon.
*
*/
ClockWidget w;
double fraction_of_a_circle;
{
double cos();
double sin();
/*
* A full circle is 2 PI radians.
* Angles are measured from 12 o'clock, clockwise increasing.
* Since in X, +x is to the right and +y is downward:
*
* x = x0 + r * sin(theta)
* y = y0 - r * cos(theta)
*
*/
/*
* Order of points when drawing the hand.
*
* 1,4
* / \
* / \
* / \
* 2 ------- 3
*/
SetSeg(w,
/* 2 */
}
/*
* DrawSecond - Draws the second hand (diamond).
*
* length is the maximum length of the hand.
* width is the half-width of the hand.
* offset is direct distance from center to tail end.
* Fraction_of_a_circle is a fraction between 0 and 1 (inclusive) indicating
* how far around the circle (clockwise) from high noon.
*
*/
ClockWidget w;
double fraction_of_a_circle;
{
register int mid;
Position x, y;
double cos();
double sin();
/*
* A full circle is 2 PI radians.
* Angles are measured from 12 o'clock, clockwise increasing.
* Since in X, +x is to the right and +y is downward:
*
* x = x0 + r * sin(theta)
* y = y0 - r * cos(theta)
*
*/
/*
* Order of points when drawing the hand.
*
* 1,5
* / \
* / \
* / \
* 2< >4
* \ /
* \ /
* \ /
* - 3
* |
* |
* offset
* |
* |
* - + center
*/
/*1 ---- 2 */
SetSeg(w,
w->clock.segbuffptr->x = x;
w->clock.segbuffptr++->y = y;
}
ClockWidget w;
{
}
/*
* Draw the clock face (every fifth tick-mark is longer
* than the others).
*/
static void DrawClockFace(w)
ClockWidget w;
{
register int i;
for (i = 0; i < 60; i++)
DrawLine(w, ( (i % 5) == 0 ?
w->clock.second_hand_length :
/* Changed last argument to DrawLine from i/60. to i due
* to compiler bug. Updated DrawLine function to reflect this.
*/
/*
* Go ahead and draw it.
*/
}
static int round(x)
double x;
{
return(x >= 0.0 ? (int)(x + .5) : (int)(x - .5));
}
/* ARGSUSED */
{
/* first check for changes to clock-specific resources. We'll accept all
the changes, but may need to do some computations first. */
}
myXGCV.line_width = 0;
}
myXGCV.line_width = 0;
}
}
myXGCV.line_width = 0;
}
return (redisplay);
}