home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk427.lzh
/
STV
/
source
/
display.c
next >
Wrap
C/C++ Source or Header
|
1991-01-09
|
6KB
|
274 lines
/*********************************
* DISPLAY 09/29/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"
/************************
* STATISTICS STRUCTURE
*************************/
struct Statistics stats; /* GLOBAL */
/*
Where is everything initialized?
Top .......... initialize()
PrevTop ...... initialize()
Rows ......... window_resized()
Cols ......... window_resized()
LeftEdge ..... window_resized()
RightEdge .... window_resized()
TopEdge ...... window_resized()
BottomEdge ... window_resized()
VCenter ...... window_resized()
Font ......... window_open()
TextWidth .... window_open()
TextHeight ... window_open()
Baseline ..... window_open()
VPropPot ..... initialize()
VPropBody .... initialize()
Scrolling .... initialize()
Propping ..... initialize()
*/
/************
* END DOWN
*************/
/*
This procedure displays the last line of the file (if it isn't already
displayed) in the bottom of the window.
*/
void end_down( void )
{
int max = current_file.Lines - stats.Rows;
/* if the last line isn't already displayed */
if (stats.Top < max)
{
/* set the top line so the last line will be at the bottom of the window */
stats.Top = max;
text_display();
modify_vprop();
}
}
/**********
* END UP
***********/
/*
This procedure displays the first line of the file (if it isn't already
displayed).
*/
void end_up( void )
{
/* if not already at the top of the file */
if (stats.Top)
{
stats.Top = 0;
text_display();
modify_vprop();
}
}
/**************
* INITIALIZE
***************/
/*
This procedure initializes the Statistics structure after each file is loaded.
*/
void initialize( void )
{
stats.Top =
stats.PrevTop =
stats.VPropPot =
stats.Scrolling =
stats.Propping = 0;
stats.VPropBody = current_file.Lines > stats.Rows ?
((long)stats.Rows * MAXBODY) / current_file.Lines : MAXBODY;
modify_vprop();
}
/**************
* LINE CHECK
***************/
/*
This procedure makes sure the Top value is correct.
*/
void line_check( void )
{
int diff;
if ((diff = stats.Top - current_file.Lines + stats.Rows) > 0)
if ((stats.Top -= diff) < 0)
stats.Top = 0;
}
/*************
* LINE DOWN
**************/
/*
This procedure displays the next line of text (unless the final line of
text is currently displayed).
*/
void line_down( BOOL modify )
/* modify ... whether to modify prop gadget */
{
if (stats.Top + stats.Rows < current_file.Lines)
{
stats.Top++;
ScrollRaster( rp, 0L, (long)stats.TextHeight,
(long)stats.LeftEdge, (long)stats.TopEdge,
(long)stats.RightEdge, (long)stats.BottomEdge );
text_line( stats.Rows-1 );
if (modify) modify_vprop();
}
}
/***********
* LINE UP
************/
/*
This procedure displays the previous line of text (unless the first line of
text is currently displayed).
*/
void line_up( BOOL modify )
/* modify ... whether to modify prop gadget */
{
if (stats.Top > 0)
{
stats.Top--;
ScrollRaster( rp, 0L, -(long)stats.TextHeight,
(long)stats.LeftEdge, (long)stats.TopEdge,
(long)stats.RightEdge, (long)stats.BottomEdge );
text_line( 0 );
if (modify) modify_vprop();
}
}
/*************
* PAGE DOWN
**************/
/*
This procedure displays the next page of text.
*/
void page_down( void )
{
int max = current_file.Lines - stats.Rows;
/* if not already at the bottom of the display */
if (stats.Top < max)
{
/* move down one page */
stats.Top += stats.Rows;
/* if moved past bottom, set to bottom of display */
if (stats.Top > max)
stats.Top = max;
text_display();
modify_vprop();
}
}
/***********
* PAGE UP
************/
/*
This procedure displays the previous page of text.
*/
void page_up( void )
{
/* if not already at the top of the file */
if (stats.Top)
{
/* move up one page */
stats.Top -= stats.Rows;
if (stats.Top < 0)
stats.Top = 0;
text_display();
modify_vprop();
}
}
/*******************
* REFRESH DISPLAY
********************/
/*
This procedure checks to make sure all of the window values are correct,
redisplays the current file, and modifies the prop gadget.
*/
void refresh_display( void )
{
BeginRefresh( win );
EndRefresh( win, TRUE );
window_resized();
SetAPen( rp, BLUE );
RectFill( rp, (long)win->BorderLeft, (long)win->BorderTop,
(long)(win->Width - win->BorderRight),
(long)(win->Height - win->BorderBottom) );
text_display();
modify_vprop();
}
/******************
* SCROLL DISPLAY
*******************/
/*
This procedure scrolls the display based on the current mouse position.
Placing the pointer all the way at or below the bottom of the window will
cause the display to jump to the end of the file. Placing the pointer at or
above the top of the window will cause the display to jump to the beginning
of the file. Otherwise, the display will scroll either up or down based on
the vertical position of the mouse, and a delay will be added if the mouse is
close to the center.
*/
/* how far from center slow-down in scrolling begins */
#define SCROLL_VERT 32
void scroll_display( void )
{
long wait; /* how long to delay scroll */
if (win->MouseY <= 0)
page_up();
else if (win->MouseY >= win->Height - 1)
page_down();
wait = win->MouseY - stats.VCenter;
if (wait > 0)
line_down( YES );
else if (wait < 0)
{
line_up( YES );
wait = -wait;
}
if (wait < SCROLL_VERT)
Delay( SCROLL_VERT - wait );
}