Category : C++ Source Code
Archive   : CPP_GRPH.ZIP
Filename : SCREEN.CPP

 
Output of file : SCREEN.CPP contained in archive : CPP_GRPH.ZIP
#include "screen.hpp"

Screen::Screen()

{
// define the global screen reference, so that the
// individual screen subparts can be linked in before
// the constructor returns
CurrentScreen = this;

// use a blue background for the work area
background_color = BLUE;

// create the page selector buttons
page = new PageSelector();

// start with no page selected
work_area = 0;
}


void Screen::DisplayTemplate()
{
// make the screen background gray
BOX_TYPE screen;
screen.x1 = SCREEN_X1;
screen.y1 = SCREEN_Y1;
screen.x2 = SCREEN_X2;
screen.y2 = SCREEN_Y2;
GraphicsHandler->FillBox(background_color, &screen);

// display the page template
page->Display();
}

void Screen::ClearArea(int x1, int y1, int x2, int y2)
{
display_list. GotoBeginning();
for (int i = 0;
i < display_list.Size();
i++, display_list++) {
Icon* icon = display_list. CurrentItem();
if (icon == 0) continue;

// skip objects not in area of interest
if (icon->x2 < x1) continue;
if (icon->x1 > x2) continue;
if (icon->y2 < y1) continue;
if (icon->y1 > y2) continue;
delete icon;
}
}



void Screen::ClearWorkArea()
{
if (work_area) {
delete work_area;
ReDraw(WORK_PAGE_X1, WORK_PAGE_Y1,
WORK_PAGE_X2, WORK_PAGE_Y2);
work_area = 0;
}
}



void Screen::NewWorkArea(Icon* icon)
{
work_area = icon;
}


void Screen::DisplayWorkArea()
{
if (work_area)
work_area->Display();
}


void Screen::ReDraw(int x1, int y1, int x2, int y2)
{

// clear the selected screen area
BOX_TYPE box;
box.x1 = x1;
box.y1 = y1;
box.x2 = x2;
box.y2 = y2;
GraphicsHandler-> FillBox(background_color, &box);

// go to the beginning of the display list
display_list. GotoBeginning();

// look for any icons invading the selected area
for (int i = 0;
i < display_list. Size();
i++, display_list++) {

// get the next icon from the display list
Icon* icon = display_list. CurrentItem();
if (icon == 0) continue; // no icon: ignore it

// skip objects not in area of interest
if (icon->x2 < x1) continue;
if (icon->x1 > x2) continue;
if (icon->y2 < y1) continue;
if (icon->y1 > y2) continue;

// we found an icon that needs to be repainted.
icon->Display();
}
}

void Screen::Update()
{
// go to the beginning of the display list
display_list. GotoBeginning();

// forward traverse the entire display list
for (int i = 0;
i < display_list. Size();
i++, display_list++) {

Icon* icon = display_list. CurrentItem();
// ignore null icons
if (icon == 0) continue;

// attempt to update the icon
icon->Update();
}
}


void Screen::AddItem(Icon* icon)
{
// go to the end of the display list
display_list. GotoEnd();

// insert the icon
display_list. AddItem(icon);
}



void Screen::RemoveItem(Icon* icon)
{
// search for menu window in screen_list
// and delete it
display_list. RemoveItem(icon);
}


void Screen::LeftButtonChanged(int x, int y, int status)
{
if (status == MOUSE_LEFT_BUTTON) {
// mouse button is pressed:
// see what icon was hit
left_button_icon = CurrentIcon(x, y);

if (left_button_icon == 0) return;
left_button_icon->LeftButtonPressed();
}
else {
// mouse button was released
if (left_button_icon == 0) return;
left_button_icon->LeftButtonReleased();
}
}

void Screen::LeftButtonDragged(int x, int y,
int deltax, int deltay, int status)
{
// see if an icon was hit
Icon* icon = CurrentIcon(x, y);
if (icon == 0) return;

// it was: invoke it
icon->LeftButtonDragged(deltax, deltay, status);
}


Icon* Screen::CurrentIcon(int x, int y)
{
Icon* object;

// go to the end of the display list
display_list. GotoEnd();

// backward traverse the entire list
for (int i = 0;
i < display_list. Size();
i++, display_list--) {

object = display_list. CurrentItem();

// see if the mouse is inside this object
if ( (x >= object->x1) && (x <= object->x2) ) {
if ( (y >= object->y1) && (y <= object->y2) )

// it is: return a pointer to the icon
return object;
}
}
/* no icon found: return a null pointer */
return (Icon*) 0;
}



void Screen::KeyTyped(int x, int y, int key)
{
Icon* icon = CurrentIcon(x, y);

if (icon)
icon->KeyTyped(key);
}



Screen::~Screen()
{
delete page;
}



  3 Responses to “Category : C++ Source Code
Archive   : CPP_GRPH.ZIP
Filename : SCREEN.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/