File: message.cpp

package info (click to toggle)
openssn 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,340 kB
  • sloc: cpp: 10,973; makefile: 80
file content (97 lines) | stat: -rw-r--r-- 3,070 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
                          msg.cpp  -  description
                             -------------------
    begin                : Monday Jan 13 2003
    copyright            : (C) 2003 by Michael Bridak
    email                : michael.bridak@verizon.net
$Id: message.cpp,v 1.7 2003/09/21 21:52:40 mbridak Exp $
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License.     *
 *    .                                   *
 *                                                                         *
 ***************************************************************************/

#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "files.h"
#include "dfont.h"
#include "message.h"

//using namespace std;

msg::msg(){
	//clear out garbage from buffer. 
	for (int x = 0; x < 20; x++){
		buffer[x][0]= '\0';
	}

}

msg::~msg(){
	//Our default Destructor...
}
void msg::InitGraphics(){

	screen = SDL_GetVideoSurface();
	SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 72, 16,
			screen->format->Rmask,
			screen->format->Gmask,
			screen->format->Bmask,
			screen->format->Amask);
	messagewindow=SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
	textcolor = SDL_MapRGB(screen->format, 192, 255, 6);
	black = SDL_MapRGB(screen->format, 0, 0, 0);
	white = SDL_MapRGB(screen->format, 255, 255, 255);
	red = SDL_MapRGB(screen->format, 255, 99, 20);
	green = SDL_MapRGB(screen->format, 0, 255, 0);
	yellow = SDL_MapRGB(screen->format, 216, 255, 0);

}

void msg::post_message(char *temp_string){
	for (int x = 1; x < 20; x++){
		// buffer[x-1]=buffer[x];
             strcpy(buffer[x-1], buffer[x]);
	}
	strcpy(buffer[19], temp_string);
	//display_message();
}
void msg::display_message(){
	char filename1[] = "images/font.png";
	char filename2[] = "data/font.dat";
	static DFont font(filename1, filename2);
	//Clearout window contents
	SDL_Rect rectangle;
	SDL_Rect destination_rectangle;
	SDL_Rect source_rectangle;
	rectangle.x=0;
	rectangle.y=0;  
	rectangle.h=72;   
	rectangle.w=800;
	SDL_FillRect(messagewindow, &rectangle, black);

	//print bottom 4 lines of buffer[]
	for (int x = 16; x < 20; x++){
		font.PutString(messagewindow, 5,(15*(x-15))-6, buffer[x]);
	}
	
	//paste surface into screen
	source_rectangle.x = 0;
	source_rectangle.y = 0;
	source_rectangle.h = 72;
	source_rectangle.w = 800;

	destination_rectangle.x = 175;
	destination_rectangle.y = 15;
	destination_rectangle.h = 72;
	destination_rectangle.w = 800;
	SDL_BlitSurface(messagewindow, &source_rectangle, screen, &destination_rectangle);
	SDL_UpdateRects(screen, 1, &destination_rectangle);
}