mwm@violet.berkeley.edu.UUCP (09/02/87)
This is a throwaway from a year ago. I never did much with it, but
recently needed part of it. I decided someone might be able to put it
to good use, or be inspired (huh?) by it.
Notes:
1) There are better ways to do many of the things I do here. I ain't
gonna fix it.
2) I tweaked it mildly just before posting it. It ought to work, but
there may be some oddness near the edges.
3) What I would like to see is this, my menu-bar clock/free memory
monitor and popcli integrated. There's enough shared functionality to
make it reasonable. If you wanna try, please e-mail me for the latest
version of said menu-bar clock/fmm.
4) No shar. Don't forget the signature line.
<mike
/*
* blackout - just black the screen out, and put and draw something that
* moves to show that we're up. It has to move so as not to mangle
* the phospher in one spot.
*
* Copyright (c) 1986, Mike Meyer
*
* Permission is hereby granted to distribute this program for any purposes
* whatsoever, so long as this notice, including the above copyright, is
* included with the distribution. Unlike other people, I don't care if you
* make money off of this, so long as I get credit for having written it.
*/
#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <devices/timer.h>
#include <libraries/dos.h>
#include <intuition/intuition.h>
#include <stdio.h>
/*
* Configuration defines:
*
* INTENSITY is a number between 0 and 15, 0 being black, 15 being
* white.
*
* WAIT-TIME controls the speed the picture moves at.
* It's the number of seconds to wait between moves. If you've got
* the clock picture, it's also the update frequency of the clock.
*/
#define INTENSITY 15
#define WAIT_TIME 1
struct NewScreen New_Screen = {
0, 0, /* Top left corner */
640, 200, /* Full hires, interlaced screen */
1, /* Only need two colors */
0, 1, /* Standard pens */
HIRES, /* Didn't I tell you that? */
CUSTOMSCREEN, /* Of course! */
(struct TextAttr *) NULL,
"Blackout!",
(struct Gadget *) NULL,
(struct BitMap *) NULL
} ;
static struct NewWindow New_Window = {
0, 0, /* Start in the upper left */
640, 200, /* and cover the whole screen */
-1, -1, /* Default pens */
MOUSEBUTTONS, /* Catching both buttons to restart */
BORDERLESS | ACTIVATE /* A window that gets it all */
| SMART_REFRESH | NOCAREREFRESH | BACKDROP | RMBTRAP,
(struct Gadget *) NULL,
(struct Image *) NULL,
"", /* Empty title */
(struct Screen *) NULL, /* Filled in later */
(struct BitMap *) NULL,
0, 0, 0, 0, /* no change sizes, doesn't matter */
CUSTOMSCREEN, /* Natch! */
} ;
static char Date_Buffer[11] ; /* Now you know where the time goes! */
static struct IntuiText Date_Text = {
1, 0, /* Use the standard pen colors */
JAM2, /* Use both of them */
29, 1, /* in the upper left-hand corner */
(struct TextAttr *) NULL, /* Use default text */
Date_Buffer, /* Buffer for time */
(struct IntuiText *) NULL /* All of text */
} ;
static UWORD My_Pointer[8] ;
#define INTUITION_REV 1
#define GRAPHICS_REV 1
struct IntuitionBase *IntuitionBase = NULL ;
struct GfxBase *GfxBase = NULL ;
struct Screen *My_Screen = NULL, *OpenScreen() ;
struct Window *My_Window = NULL, *OpenWindow() ;
struct timerequest Time_Req ;
struct MsgPort *Timer_Port = NULL, *CreatePort() ;
short cli = FALSE ;
void done(int, char *) ;
void
main(argc, argv) int argc; char *argv; {
register short hours, minutes, seconds ;
register short x_delta = 0, y_delta = 0, x_where, y_where ;
UWORD Color_Map[2] ;
register char *buffer = Date_Buffer ;
struct DateStamp now ;
struct IntuiMessage *Msg, *GetMsg() ;
cli = argc != 0 ;
if ((IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV)) == NULL)
done(20, "Can't open intuition library") ;
if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",
GRAPHICS_REV)) == NULL)
done(20, "Can't open open graphics library") ;
if ((My_Screen = OpenScreen(&New_Screen)) == NULL)
done(20, "Can't open screen") ;
New_Window . Screen = My_Screen ;
if ((My_Window = OpenWindow(&New_Window)) == NULL)
done(20, "Can't open window") ;
if ((Timer_Port = CreatePort("Timer Port", 0)) == NULL)
done(20, "Can't create timer port") ;
if (OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Time_Req, 0) != NULL)
done(20, "Can't open timer device") ;
Time_Req . tr_node . io_Message . mn_ReplyPort = Timer_Port ;
Time_Req . tr_node . io_Command = TR_ADDREQUEST ;
Time_Req . tr_node . io_Flags = Time_Req . tr_node . io_Error = 0 ;
/* Black out the screen */
Color_Map[0] = 0 ; /* BLACKEST BLACK for the background */
Color_Map[1] = (INTENSITY << 8) | (INTENSITY << 4) | INTENSITY ;
LoadRGB4(&(My_Screen -> ViewPort), Color_Map, 2) ;
ShowTitle(My_Screen, FALSE) ;
SetPointer(My_Window, My_Pointer, 2, 2, 1, 1) ;
SetRast(My_Window -> RPort, 0) ;
DateStamp(&now) ;
srand(now . ds_Tick) ;
minutes = 0 ; /* Used to trigger first setting of deltas */
x_where = 310 ;
y_where = 95 ;
buffer[3] = buffer[6] = ':' ;
buffer[0] = buffer[9] = ' ' ;
for (;;) {
if (minutes == 0) {
while (x_delta == 0)
x_delta = (rand() >> 4) % 13 - 6 ;
while (y_delta == 0)
y_delta = (rand() >> 4) % 9 - 4 ;
}
DateStamp(&now) ;
hours = now . ds_Minute / 60 ;
minutes = now . ds_Minute % 60 ;
seconds = now . ds_Tick / TICKS_PER_SECOND ;
buffer[1] = hours / 10 + '0' ;
if (buffer[1] == '0') buffer[1] = ' ' ;
buffer[2] = hours % 10 + '0' ;
buffer[4] = minutes / 10 + '0' ;
buffer[5] = minutes % 10 + '0' ;
buffer[7] = seconds / 10 + '0' ;
buffer[8] = seconds % 10 + '0' ;
SetRast(My_Window -> RPort, 0) ;
PrintIText(My_Window -> RPort, &Date_Text, x_where, y_where) ;
Time_Req . tr_time . tv_secs = WAIT_TIME ;
Time_Req . tr_time . tv_micro = 0 ;
SendIO((char *) &Time_Req . tr_node) ;
Wait(1 << My_Window -> UserPort -> mp_SigBit
| 1 << Timer_Port -> mp_SigBit) ;
if (Msg = GetMsg(My_Window -> UserPort)) {
ReplyMsg(Msg) ;
done(0, "exit") ;
}
(void) GetMsg(Timer_Port) ;
/* Now, move the window */
if (x_where + x_delta > 620
|| x_where + x_delta < 0) x_delta = -x_delta ;
if (y_where + y_delta > 390
|| y_where + y_delta < 0) y_delta = -y_delta ;
x_where += x_delta ;
y_where += y_delta ;
}
done(20, "Dropped out of forever loop") ;
}
/*
* done - close things, and then exit.
*/
void
done(how, why) int how; char *why; {
AbortIO((char *) &Time_Req . tr_node) ;
if (Time_Req . tr_node . io_Message . mn_ReplyPort != NULL)
CloseDevice(&Time_Req) ;
if (Timer_Port != NULL) DeletePort(Timer_Port) ;
if (My_Window != NULL) CloseWindow(My_Window) ;
if (My_Screen != NULL) CloseScreen(My_Screen) ;
if (GfxBase != NULL) CloseLibrary(GfxBase) ;
if (IntuitionBase != NULL) CloseLibrary(IntuitionBase) ;
(void) OpenWorkBench() ;
if (cli) printf("blackout: %s\n", why) ;
exit(how) ;
}
--
Take a magic carpet to the olden days Mike Meyer
To a mythical land where everybody lays mwm@berkeley.edu
Around in the clouds in a happy daze ucbvax!mwm
In Kizmiaz ... Kizmiaz mwm@ucbjade.BITNETmwm@eris.BERKELEY.EDU (Mike (My watch has windows) Meyer) (09/02/87)
In article <4960@jade.BERKELEY.EDU> I wrote: <2) I tweaked it mildly just before posting it. It ought to work, but <there may be some oddness near the edges. Naturally, one of those bit me. Also, want to add: 5) I don't think this is worth filling space in a source archive. If a moderator somewhere feels different, feel free to make it do so. Now, on to the important part. The marked lines should change /* Now, move the window */ if (x_where + x_delta > 620 || x_where + x_delta < 0) x_delta = -x_delta ; ! if (y_where + y_delta > 390 || y_where + y_delta < 0) y_delta = -y_delta ; to if (y_where + y_delta > 190 Sigh, <mike P.S. - I want to take this chance to congratulate Leo on "The dream goes berserk," since no one else has done so here yet! Nice job, Leo. -- ICUROK2C, ICUROK2. Mike Meyer ICUROK2C, ICWR2. mwm@berkeley.edu URAQT, I WANT U2. ucbvax!mwm OO2EZ, I WANT U2. mwm@ucbjade.BITNET