home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk427.lzh
/
STV
/
source
/
gadget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-09
|
5KB
|
170 lines
/*********************************
* GADGET 09/28/90
* Source file for STV
* © Copyright 1990 Timm Martin
* All Rights Reserved Worldwide
**********************************/
#include <exec/types.h>
#include <functions.h>
#include <intuition/intuition.h>
#include "func.h"
#include "main.h"
/***************
* PROP GADGET
****************/
struct Image vprop_image;
#define VPROP_FLAGS AUTOKNOB|FREEVERT |PROPBORDERLESS
struct PropInfo vprop_info =
{
/* USHORT Flags */ VPROP_FLAGS,
/* USHORT HorizPot */ 0,
/* USHORT VertPot */ 0,
/* USHORT HorizBody */ 0,
/* USHORT VertBody */ MAXBODY,
/* USHORT CWidth */ 0,
/* USHORT CHeight */ 0,
/* USHORT HPotRes */ 0,
/* USHORT VPotRes */ 0,
/* USHORT LeftBorder */ 0,
/* USHORT TopBorder */ 0,
};
struct Gadget vprop_gadget =
{
/* struct Gadget * NextGadget */ NULL,
/* SHORT LeftEdge */ LATER,
/* SHORT TopEdge */ LATER,
/* SHORT Width */ LATER,
/* SHORT Height */ LATER,
/* USHORT Flags */ GADGHCOMP | GRELHEIGHT | GRELRIGHT,
/* USHORT Activation */ GADGIMMEDIATE,
/* USHORT GadgetType */ PROPGADGET,
/* APTR GadgetRender */ (APTR)&vprop_image,
/* APTR SelectRender */ NULL,
/* struct IntuiText * GadgetText */ NULL,
/* LONG MutualExclude */ NULL,
/* APTR SpecialInfo */ (APTR)&vprop_info,
/* USHORT GadgetID */ 1,
/* APTR UserData */ NULL,
};
/**************
* GADGET ADD
***************/
/*
This procedure sets the prop gadget size and position, adds it to the window,
and refreshes it.
*/
/* sizing gadget height under WB 1.x */ #define HEIGHT1 9
/* sizing gadget height under WB 2.x */ #define HEIGHT2 10
/* sizing gadget width under WB 1.x */ #define WIDTH1 15
/* sizing gadget width under WB 2.x */ #define WIDTH2 17
/* width of window border */ #define WIDTH 3
void gadget_add( void )
{
if (wb2)
{
vprop_gadget.LeftEdge = -WIDTH2 + 2;
vprop_gadget.Width = WIDTH2 - WIDTH;
vprop_gadget.TopEdge = win->BorderTop + 1;
vprop_gadget.Height = -vprop_gadget.TopEdge - HEIGHT2 - 1;
}
else
{
vprop_gadget.LeftEdge = -WIDTH1;
vprop_gadget.Width = WIDTH1 - WIDTH;
vprop_gadget.TopEdge = win->BorderTop;
vprop_gadget.Height = -vprop_gadget.TopEdge - HEIGHT1 - 1;
}
AddGadget( win, &vprop_gadget, -1L );
RefreshGadgets( &vprop_gadget, win, NULL );
}
/******************
* GADGET CURRENT
*******************/
/*
This procedure handles the user moving the prop gadget.
*/
void gadget_current( void )
{
/* determine if user is still fiddling with the gadget */
PROPPING = vprop_gadget.Flags & SELECTED;
/* adjust the display position; if still selected, check if moved */
move_vprop( PROPPING );
}
/************************
* MODIFY Vertical PROP
*************************/
/*
This procedure sets the position of the vertical prop gadget based on the
current Top value.
*/
void modify_vprop( void )
{
stats.VPropPot = current_file.Lines == stats.Rows ? 0 :
(stats.Top * MAXPOT) / (current_file.Lines - stats.Rows);
/* stats.VPropBody calculated only once in initialize() */
NewModifyProp( &vprop_gadget, win, NULL, VPROP_FLAGS,
0L, stats.VPropPot, 0L, stats.VPropBody, 1L );
}
/**********************
* MOVE Vertical PROP
***********************/
/*
This procedure calculates the new top line based on the current position of
the vertical prop gadget. It then checks if the display should be scrolled
(the change is within the predefined limit of SCROLL), completely
redisplayed (the change is greater than the limit), or just left alone (there
is no change).
*/
#define SCROLL 20
void move_vprop( BOOL check )
/*
check ... if should check if moved before doing anything. This will be
YES while the gadget is active, meaning that this procedure
must check if the gadget has moved. This will be NO when the
user lets up on the LMB.
*/
{
int scroll;
long top;
top = current_file.Lines > stats.Rows ?
(vprop_info.VertPot * (current_file.Lines - stats.Rows)) / MAXPOT : 0;
if (!check ||
(scroll = stats.PrevTop - top) < -SCROLL || scroll > SCROLL)
{
stats.Top = top;
text_display();
}
else if (scroll < 0)
line_down( NO );
else if (scroll > 0)
line_up( NO );
/* else didn't change so don't move */
/* record new top position in PrevTop for next time */
stats.PrevTop = stats.Top;
}