home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: dpaint.c,v 2.7 91/03/27 16:45:29 billr Exp $
- */
- /*
- * dpaint.c
- *
- * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
- *
- * Original source Copyright (C) 1987, Sun Microsystems, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify this program in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- *
- *
- * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Changes and additions Copyright (C) 1988, 1989, 1991 Tektronix, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify the modifications in source
- * or binary form as long as they are not sold for profit and this copyright
- * notice remains intact.
- */
- /***************************************************
- * *
- * Artistic routines that draw in the main *
- * subwindow for the day display. *
- * *
- ***************************************************/
-
- #include <ctype.h>
- #include <sys/time.h>
- #include <stdio.h>
- #ifndef NOTOOL
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #endif
- #include "ct.h"
- #include "paint.h"
- #ifndef NOTOOL
- #include "riseset.h"
- #define J1970 2440587.5 /* VAX clock Epoch 1970 Jan 1 (0h UT) */
-
- #ifndef NO_SUN_MOON
- extern Frame mframe, sframe;
- extern Canvas mcanvas, scanvas;
- extern Panel_item mdate_pi, sdate_pi;
- #endif /* NO_SUN_MOON */
- extern Pixrect *leftarrow, *rightarrow;
- extern Pixrect *arrowshaft_pr, *arrowhead_pr;
- extern Pixrect *gr_arrowshaft_pr, *gr_arrowhead_pr;
- extern char riseset_buf[][64];
- extern int old_slot;
- #endif /* NOTOOL */
- extern int day_message_size;
- extern int show_future;
- extern int new_entry;
- extern int findex; /* index into struct future array */
- extern struct appt_entry future[];
-
-
- #ifndef NOTOOL
- /*
- * This one draws the current selected day in the
- * main subwindow.
- */
-
- draw_day()
- {
- draw_day1();
- draw_future_appts();
- #ifndef NO_SUN_MOON
- if (sframe)
- write_sun_data();
- if (mframe)
- write_moon_data();
- #endif
- }
-
- /*
- * Draw main day page without future appts or Sun/Moon data
- */
- draw_day1()
- {
- int i;
-
- lock_cursors();
- fix_current_day();
- working(TRUE);
- pw_batch_on(main_pixwin);
- draw_day_outline();
- pw_batch_off(main_pixwin);
- i = get_day_appts();
- working(FALSE);
- if (i) {
- draw_day_appts();
- }
- day_is_open = TRUE;
- unlock_cursors();
- }
-
- /*
- * Utility for draw_day ... draws the outline of a day.
- */
- draw_day_outline()
- {
- char timestring[6], daystring[31], buf[64], *src;
- int x, y, starty, i, d;
- Rect *rect;
-
- /* First erase the window. */
- rect = (Rect *) window_get(canvas, WIN_RECT);
- pw_writebackground(main_pixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
- old_slot = -1; /* text cursor no longer displayed */
-
- /* Calculate coords of top-left corner of big box. */
- x = (rect->r_width - dayslot_width) / 2;
- starty = y = (rect->r_height - (n_slots * dayslot_height)) / 2;
-
- /* Format daystring to say, for example, */
- if (day_first)
- /* Tuesday, 13 March 1990 */
- sprintf(daystring, "%s %d %s %d",
- daynames[current.tm_wday], current.tm_mday,
- monthnames[current.tm_mon], 1900 + current.tm_year);
- else
- /* Tuesday, March 13, 1990 */
- sprintf(daystring, "%s %s %d, %d",
- daynames[current.tm_wday], monthnames[current.tm_mon],
- current.tm_mday, 1900 + current.tm_year);
- pw_text(main_pixwin, (rect->r_width - bigfont->pf_defaultsize.x*strlen(daystring))/2, starty/2 + 7,
- PIX_SRC, bigfont, daystring);
-
- for (i=0; i<n_slots; i++) { /* Init and draw each 30 minute slot. */
- slots[i].slot_pos.top = y;
- slots[i].slot_pos.left = x;
- slots[i].slot_pos.bottom = y + dayslot_height + 1;
- slots[i].slot_pos.right = x + dayslot_width + 1;
- slots[i].moreb_pos.top = y;
- slots[i].moreb_pos.left = rect->r_width - 8 - morebutton->pr_size.x;
- slots[i].moreb_pos.bottom = y + morebutton->pr_size.y;
- slots[i].moreb_pos.right = rect->r_width - 8;
- slots[i].larrow_pos.top = slots[i].slot_pos.top+(dayslot_height-leftarrow->pr_size.y)/2;
- slots[i].larrow_pos.left = slots[i].slot_pos.right + 8;
- slots[i].larrow_pos.bottom = slots[i].larrow_pos.top + leftarrow->pr_size.y;
- slots[i].larrow_pos.right = slots[i].larrow_pos.left + leftarrow->pr_size.x;
- slots[i].rarrow_pos.top = slots[i].larrow_pos.top;
- slots[i].rarrow_pos.left = slots[i].larrow_pos.right + 8;
- slots[i].rarrow_pos.bottom = slots[i].larrow_pos.bottom;
- slots[i].rarrow_pos.right = slots[i].rarrow_pos.left + rightarrow->pr_size.x;
- if (!ymd_compare(current, today))
- pw_write(main_pixwin,x,y,dayslot_width,dayslot_height,PIX_SRC,timeslot_td_pr,0,0);
- else
- pw_write(main_pixwin,x,y,dayslot_width,dayslot_height,PIX_SRC,timeslot_pr,0,0);
- if (i < n_tslots) {
- /* display time */
- if (hour24)
- sprintf(timestring, "%2d:%s",
- start_hour+(i/2),
- i%2 == 0 ? "00" : "30");
- else
- sprintf(timestring, "%2d:%s%s",
- (start_hour+(i/2))%12 == 0 ? 12 : (start_hour+(i/2))%12,
- i%2 == 0 ? "00" : "30", (start_hour+(i/2) < 12 ? "am" : "pm"));
- } else if (i == n_tslots) {
- sprintf(timestring, "Notes");
- } else {
- sprintf(timestring, " ");
- }
- pw_text(main_pixwin,x-9*font->pf_defaultsize.x,y+font->pf_defaultsize.y,PIX_SRC,font,timestring);
- y += dayslot_height - 1;
- }
-
- pw_vector(main_pixwin,x,starty,x+dayslot_width-1,starty,PIX_SET,1);
- pw_vector(main_pixwin,x,y,x+dayslot_width-1,y,PIX_SET,1);
- y += (dayslot_height - 1) * 2;
- sprintf(buf,
- "Day of year: %d -- %d days remaining. Week number: %d",
- day_of_year((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900),
- days_remaining_in_year((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900),
- week_number());
- pw_text(main_pixwin, x, y, PIX_SRC, font, buf);
- sun_moon_buttons(TRUE);
- print_button(TRUE);
- }
- #endif /* NOTOOL */
-
- #ifndef NOTOOL
- /* draw in todays appointments */
- draw_day_appts()
- {
- int slotno, narrows, i;
- int offset, x, y;
-
- pw_batch_on(main_pixwin);
- /* first clear all the slots */
- for (slotno=0; slotno<n_slots; slotno++) {
- slots[slotno].arrow_pos = 0;
- x = slots[slotno].slot_pos.left;
- y = slots[slotno].slot_pos.top;
- if (!ymd_compare(current, today))
- pw_write(main_pixwin,x,y,dayslot_width,
- dayslot_height,PIX_SRC,timeslot_td_pr,0,0);
- else
- pw_write(main_pixwin,x+1,y+1,dayslot_width-2,
- dayslot_height-2,PIX_CLR,NULL,0,0);
- }
-
- /* draw in current info */
- for (slotno=0; slotno<n_slots; slotno++) {
- if (slots[slotno].active) {
- rewrite_string(slotno, JUSTIFY_LEFT);
- if ((narrows = slots[slotno].cur_appt->arrows) > 0) {
- /* find first free position for arrow */
- offset = 0;
- while (slots[slotno].arrow_pos & 1<<offset)
- offset++;
- slots[slotno].arrow_pos |= 1<<offset;
- i = slotno + narrows;
- draw_arrowhead(i, offset, FALSE);
- while (--narrows > 0)
- draw_arrowshaft(--i, offset, FALSE);
- }
- more_check(slotno);
- }
- }
- pw_batch_off(main_pixwin);
- }
-
- /* Blacks out day-slot and then re-writes string. */
- rewrite_string(bi, justify)
- int bi, justify;
- {
- char slot_str[MAX_STRLEN];
- char *ptr;
- int strl, *iptr;
-
- strl = strlen(slots[bi].cur_appt->str);
- iptr = &slots[bi].cur_appt->sindex;
- if (strl < day_message_size) {
- *iptr = 0; /* just in case */
- strcpy(slot_str, slots[bi].cur_appt->str);
- /* erase any previously existing scroll arrows */
- pw_writebackground(main_pixwin, slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.top, slots[bi].rarrow_pos.right-slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.bottom-slots[bi].larrow_pos.top,
- PIX_CLR);
- } else {
- if (justify == JUSTIFY_RIGHT) {
- /* show trailing part */
- ptr = &slots[bi].cur_appt->str[strl - day_message_size + 1];
- *iptr = strl - day_message_size + 1;
- strcpy(slot_str, ptr);
- } else {
- /* show leading or indexed part */
- if (justify == JUSTIFY_LEFT)
- *iptr = 0;
- if (*iptr > (strl - day_message_size + 1))
- *iptr = strl - day_message_size + 1;
- if (strlen(&slots[bi].cur_appt->str[*iptr]) >= day_message_size-1) {
- strncpy(slot_str, &slots[bi].cur_appt->str[*iptr], day_message_size-1);
- slot_str[day_message_size-1] = '\0';
- } else
- strcpy(slot_str, &slots[bi].cur_appt->str[*iptr]);
- }
- /* display scroll arrows */
- pw_write(main_pixwin, slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.top, leftarrow->pr_size.x,
- leftarrow->pr_size.y, PIX_SRC, leftarrow, 0, 0);
- pw_write(main_pixwin, slots[bi].rarrow_pos.left,
- slots[bi].rarrow_pos.top, rightarrow->pr_size.x,
- rightarrow->pr_size.y, PIX_SRC, rightarrow, 0, 0);
- }
- pw_write(main_pixwin, slots[bi].slot_pos.left+1, slots[bi].slot_pos.top+1,
- dayslot_width-2, dayslot_height-2, PIX_SET, NULL, 0, 0);
- pw_text(main_pixwin, slots[bi].slot_pos.left+5, slots[bi].slot_pos.top+font->pf_defaultsize.y,
- PIX_NOT(PIX_SRC), font, slot_str);
- }
-
- /* display "more" button if necessary */
- more_check(slotno)
- int slotno;
- {
- int x, y, w, i, offset;
- int narrows;
- struct appt_entry *aptr;
-
- x = morebutton->pr_size.x;
- y = morebutton->pr_size.y;
-
- /* clear any previous button that may be there */
- pw_write(main_pixwin, slots[slotno].moreb_pos.left, slots[slotno].moreb_pos.top,
- x, y, PIX_CLR, NULL, 0, 0);
- /* button displayed when more than 1 reference
- * and at least one real appt for this slot.
- */
- if (slots[slotno].active > 1) {
- for (aptr=slots[slotno].first; aptr; aptr=aptr->next) {
- if (aptr == slots[slotno].cur_appt)
- continue; /* already did this one */
- if (chk_deleted(&slots[slotno], aptr))
- continue; /* ignore deleted appts */
- if ((narrows = aptr->arrows) > 0) {
- /* find first free position for arrow */
- offset = 0;
- while (slots[slotno].arrow_pos & 1<<offset)
- offset++;
- slots[slotno].arrow_pos |= 1<<offset;
- i = slotno + narrows;
- draw_arrowhead(i, offset, TRUE);
- while (--narrows > 0)
- draw_arrowshaft(--i, offset, TRUE);
- }
- }
- /* display more button to right of slot */
- pw_write(main_pixwin, slots[slotno].moreb_pos.left, slots[slotno].moreb_pos.top,
- x, y, PIX_SRC, morebutton, 0, 0);
- }
- }
-
- draw_arrowshaft(i, offset, gray)
- int i;
- int offset;
- int gray;
- {
- /* mark this position as used */
- slots[i].arrow_pos |= 1<<offset;
- /* translate to screen coordinates */
- offset = (offset + 1) * 40;
- pw_rop(main_pixwin, slots[i].slot_pos.left+1+offset, slots[i].slot_pos.top,
- 16, dayslot_height, PIX_SRC|PIX_DST,
- (gray ? gr_arrowshaft_pr : arrowshaft_pr), 0, 0);
- }
-
-
-
- draw_arrowhead(i, offset, gray)
- int i;
- int offset;
- int gray;
- {
- /* mark this position as used */
- slots[i].arrow_pos |= 1<<offset;
- /* translate to screen coordinates */
- offset = (offset + 1) * 40;
- pw_rop(main_pixwin, slots[i].slot_pos.left+1+offset, slots[i].slot_pos.top,
- 16, dayslot_height, PIX_SRC|PIX_DST,
- (gray ? gr_arrowhead_pr : arrowhead_pr), 0, 0);
- }
-
- /*
- * Routine to create popup window with future appts shown in it
- */
- draw_future_appts()
- {
- if (show_future && findex && (ymd_compare(current, today) == 0)) {
- create_future_popup();
- } else {
- /* nothing to show */
- /* destroy future appts popup, if it exists */
- if (fframe) {
- window_destroy(fframe);
- fframe = 0;
- }
- }
- }
- #endif /* NOTOOL */
-
- #ifndef NO_SUN_MOON
- /*
- * write sun data to the popup canvas
- */
- write_sun_data()
- {
- int x, y, height;
- char buf[64];
- Pixwin *spixwin;
- Rect *rect;
- struct timeval tp;
- double jdays, secs, offset;
- double julian_day();
- char *sunlight;
-
- /* first erase the window. */
- spixwin = (Pixwin *)canvas_pixwin(scanvas);
- rect = (Rect *) window_get(scanvas, WIN_RECT);
- pw_writebackground(spixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
-
- x = font->pf_defaultsize.x;
- height = y = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- if (ymd_compare(current, today) == 0) {
- /* use current time */
- write_times();
- panel_set(sdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- y += 11 * height;
- } else {
- /* convert today's date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)today.tm_mday, today.tm_mon+1, today.tm_year+1900) - J1970;
- /* seconds from 00:00 GMT to now */
- offset = tp.tv_sec - (jdays * 24. * 3600.);
- /* convert this date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900) - J1970;
- /* seconds to the same time on selected day */
- secs = (jdays * 24.0 * 3600.) + offset;
- riseset((long)secs);
- panel_set(sdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_JLD]);
- y += height;
- }
- sprintf(buf, "Sun Rise (today): %s Total Hours of", riseset_buf[B_SRD]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
-
- sprintf(buf, "Sun Set (today): %s Sunlight %5s ", riseset_buf[B_SSD],
- riseset_buf[B_LOD]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Sun Rise (tomorrow): %s", riseset_buf[B_SRT]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Sun Set (tomorrow): %s", riseset_buf[B_SST]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- }
-
- /*
- * write sun time data to the popup canvas
- */
- write_times()
- {
- int x, y, height;
- Pixwin *spixwin;
- struct timeval tp;
-
- /* only update these if displaying today's page */
- if (ymd_compare(current, today) != 0)
- return;
-
- spixwin = (Pixwin *)canvas_pixwin(scanvas);
-
- x = font->pf_defaultsize.x;
- y = height = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- riseset(tp.tv_sec);
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_GMT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_TDT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LCT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LMT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_GST]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LST]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_JLD]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LHA]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SDE]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SAZ]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SEL]);
- }
-
- /*
- * write moon data to the popup canvas
- */
- write_moon_data()
- {
- int x, y, height;
- char buf[64];
- Pixwin *mpixwin;
- Rect *rect;
- struct timeval tp;
- double jdays, secs, offset;
- double julian_day();
-
- /* first erase the window. */
- mpixwin = (Pixwin *)canvas_pixwin(mcanvas);
- rect = (Rect *) window_get(mcanvas, WIN_RECT);
- pw_writebackground(mpixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
-
- x = font->pf_defaultsize.x;
- y = height = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- if (ymd_compare(current, today) == 0) {
- /* use current time */
- riseset(tp.tv_sec);
- moon_data(tp.tv_sec);
- } else {
- /* convert today's date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)today.tm_mday, today.tm_mon+1, today.tm_year+1900) - J1970;
- /* seconds from 00:00 GMT to now */
- offset = tp.tv_sec - (jdays * 24. * 3600.);
- /* convert this date to seconds from 1-1-1970 */
- jdays = julian_day((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900) - J1970;
- /* seconds to the same time on selected day */
- secs = (jdays * 24.0 * 3600.) + offset;
- riseset((long)secs);
- moon_data((long)secs);
- }
- panel_set(mdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- y = 6 * height;
- sprintf(buf, "Moon Rise (today): %s", riseset_buf[B_MRD]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Set (today): %s", riseset_buf[B_MSD]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Rise (tomorrow): %s", riseset_buf[B_MRT]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Set (tomorrow): %s", riseset_buf[B_MST]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- }
-
- #endif /* NO_SUN_MOON */
-