Metropoli BBS
VIEWER: cursor.c MODE: TEXT (CP437)
               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                CURSOR DEMONSTRATIONM                  │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                      INCLUDES                         │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

#include <stdio.h>
#include <math.h>
#include <dos.h>

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                USER WRITTEN INCLUDES                  │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

#include "colors.h"
#include "gtools.h"
#include "gdraws.h"

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │     GLOBAL VARIABLES USED BY GRAPHICS FUNCTIONS       │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/


enum vidTypes {mda, cga, ega, compaq, other};

int color = 2;
int background_color = 0;
int LINEWIDTH=1, OPERATOR=0, ANGLE, XCENTER, YCENTER,CURSOR_X,CURSOR_Y;
unsigned long int PATTERN=0xFFFFFFFF;

unsigned long int style[8] = { 0xFFFFFFFF,0xC0C0C0C0,0xFF00FF00,0xFFF0FFF0,
                                0xF000F000,
                                0xFFFF0000,0xFFFFF0F0,0xFFF0F0F0};

unsigned int mask, cursor_pattern[2][16] = {0x8000,0xC000,0xE000,
	0xF000,0xF800,0xFC00,0xFE00,0xFF00,0xF800,0xD800,0x8C00,
        0x0C00,0x0600,0x0600,0x00,0x00,0x0100,0x0100,0x0100,0x0100,
        0x0100,0x7FFC,0x0100,0x0100,0x0100,0x0100,0x0100,0x0100};



               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                 FUNCTION DEFINITIONS                  │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/

void move_cursor(int type,int color);
void wait(char title[]);

               /*┌───────────────────────────────────────────────────────┐
                 │                                                       │
                 │                     MAIN PROGRAM                      │
                 │                                                       │
                 └───────────────────────────────────────────────────────┘*/




main()
{
        double xd,yd,ampl,aspect;
        char ch;

	cls (1);
        setMode(0x10);
        cls(1);
	write_big_str(-119,131,"CURSOR",226);
        write_vid_str(-200,-6,"DEMONSTRATION",91);
        wait("Move cursor with arrows");
        LINEWIDTH = 3;
        cls(4);
        drawRect(-309,210,310,-200,11);
        drawLine(-309,210,310,-200,11);
        drawLine(-309,-200,310,210,11);
        wait("Move cursor with arrows");
}

void wait(char title[])
{
        int tab,width,line,mode;
	static int cursor_type,cursor_color;

	cursor_type = cursor_type %2;
	cursor_color = cursor_color %8 + 8;
        mode = getMode(&width);
    	if ((mode == 0x11) || (mode == 0x12))
		line = 29;
	else
		line = 24;
	tab = (width - strlen(title))/2;
        gotoxy(tab,0);
        writString(title,WHITE,0);
        tab = (width - 33)/2;
        gotoxy(tab,line);
        writString("Press 'Enter' to continue demo...", WHITE,0);
	move_cursor(cursor_type,cursor_color);
	cursor_color--;
	cursor_type = (++cursor_type)%2;
        cls(0);
}

void move_cursor(int type,int color)
{
	int i,j,k,xoff=0,yoff=0,image_store[3][4][16],ch,fast = 1,temp;
	char far *base;

        if (type == 1)
        {
        	xoff = -8;
        	yoff = -6;
        }
	CURSOR_X = -xoff;
	CURSOR_Y = -yoff;
	temp = OPERATOR;
	OPERATOR = 0x18;
	do
	{
		for (i=0; i<16; i++)
		{
			for (j=0; j<16; j++)
			{
				mask = 0x8000 >> j;
				if ((mask & cursor_pattern[type][i]) != 0)
					plot(CURSOR_X+j+xoff+319,175 -
						((CURSOR_Y*93) >> 7)+i+yoff,
						color);
			}
		}
		ch = getch();
		if (ch == 0)
			ch = getch() + 256;
		for (i=0; i<16; i++)
		{
			for (j=0; j<16; j++)
			{
		    		mask = 0x8000 >> j;
				if ((mask & cursor_pattern[type][i]) != 0)

					plot(CURSOR_X+j+xoff+319,175 -
						((CURSOR_Y*93) >> 7)+i+yoff,
						color);
}
		}
                switch(ch)
                {
			case 27:
				fast = (++fast) % 2;
				break;

			case 333:
				if ((CURSOR_X < 303) && (fast == 0))
					CURSOR_X++;
				if ((CURSOR_X < 294) && (fast == 1))
					CURSOR_X += 10;
				break;
			case 331:
				if ((CURSOR_X > -318)  && (fast == 0))
					CURSOR_X--;
				if ((CURSOR_X > -309) && (fast == 1))
					CURSOR_X -= 10;
				break;
			case 336:
				if ((CURSOR_Y > -223) && (fast == 0))
					CURSOR_Y--;
				if ((CURSOR_Y > -214) && (fast == 1))
					CURSOR_Y -= 10;
				break;
			case 328:
				if ((CURSOR_Y < 239) && (fast == 0))
					CURSOR_Y++;
				if ((CURSOR_Y < 230) && (fast == 1))
					CURSOR_Y += 10;
				break;
		}
        }
        while (ch != 0x0D);
	OPERATOR = temp;
}

[ RETURN TO DIRECTORY ]