ReactOS  0.4.14-dev-358-gbef841c
message.c File Reference
#include <windows.h>
#include "globals.h"
#include "message.h"
#include "matrix.h"
Include dependency graph for message.c:

Go to the source code of this file.

Functions

WORD crc_msgrand (WORD reg)
 
void SetMatrixMessage (MATRIX_MESSAGE *msg, HFONT hFont, TCHAR *text)
 
void DrawMatrixMessage (MATRIX *matrix, MATRIX_MESSAGE *msg, HDC hdc)
 
void RevealMatrixMessage (MATRIX_MESSAGE *msg, int amount)
 
void ClearMatrixMessage (MATRIX_MESSAGE *msg)
 
int MessageSpeed ()
 
void DoMatrixMessage (HDC hdc, MATRIX *matrix)
 
void SetMessageFont (HWND hwnd, TCHAR *szFontName, int nPointSize, BOOL fBold)
 
MATRIX_MESSAGEInitMatrixMessage (HWND hwnd, int width, int height)
 

Function Documentation

◆ ClearMatrixMessage()

void ClearMatrixMessage ( MATRIX_MESSAGE msg)

Definition at line 129 of file message.c.

130 {
131  int x, y;
132 
133  for(x = 0; x < msg->width; x++)
134  for(y = 0; y < msg->height; y++)
135  msg->message[x][y] = 0;
136 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define msg(x)
Definition: auth_time.c:54

Referenced by DoMatrixMessage(), and InitMatrixMessage().

◆ crc_msgrand()

WORD crc_msgrand ( WORD  reg)

Definition at line 23 of file message.c.

24 {
25  const WORD mask = 0xb400;
26 
27  if(reg & 1)
28  reg = (reg >> 1) ^ mask;
29  else
30  reg = (reg >> 1);
31 
32  return reg;
33 }
GLenum GLint GLuint mask
Definition: glext.h:6028
unsigned short WORD
Definition: ntddk_ex.h:93
static int reg
Definition: i386-dis.c:1275

Referenced by RevealMatrixMessage().

◆ DoMatrixMessage()

void DoMatrixMessage ( HDC  hdc,
MATRIX matrix 
)

Definition at line 149 of file message.c.

150 {
151  MATRIX_MESSAGE *msg = matrix->message;
152 
153  int RealSpeed = MessageSpeed();
154 
155  if(g_nNumMessages > 0)
156  {
157  // nothing to do yet..
158  if(msg->counter++ < 0)
159  return;
160 
161  // has counter reached limit..clear the message
162  if(msg->counter++ == RealSpeed / 2 + (RealSpeed/4))
164 
165  // reset counter + display a new message
166  if(msg->counter >= RealSpeed)
167  {
168  // mark all message-cells as being "invisible" so the
169  // message gets cleared by the matrix decoding naturally
170 
172  msg->msgindex = crc_rand() % g_nNumMessages;
173  else
174  msg->msgindex = (msg->msgindex + 1) % g_nNumMessages;
175 
176  // make a new message..initially invisible
177  SetMatrixMessage(msg, 0, g_szMessages[msg->msgindex]);
178 
179  msg->counter = -(int)(crc_rand() % MSGSPEED_MAX);
180  }
181  // reveal the next part of the message
182  else if(msg->counter < RealSpeed / 2)
183  {
184  int w = (g_nMessageSpeed - MSGSPEED_MIN);
185  w = (1 << 16) + ((w<<16) / MSGSPEED_MAX);
186  w = (w * 3 * g_nMessageSpeed) >> 16;
187 
188  RevealMatrixMessage(msg, w + 100);
189  }
190 
191  //
192  // draw whatever part of the message is visible at this time
193  //
195  }
196 }
#define MSGSPEED_MAX
Definition: globals.h:27
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
TCHAR g_szMessages[MAX_MESSAGES][MAXMSG_LENGTH]
Definition: settings.c:13
GLuint GLenum matrix
Definition: glext.h:9407
void ClearMatrixMessage(MATRIX_MESSAGE *msg)
Definition: message.c:129
int g_nNumMessages
Definition: settings.c:14
void SetMatrixMessage(MATRIX_MESSAGE *msg, HFONT hFont, TCHAR *text)
Definition: message.c:38
void RevealMatrixMessage(MATRIX_MESSAGE *msg, int amount)
Definition: message.c:113
int g_nMessageSpeed
Definition: settings.c:15
int crc_rand()
Definition: matrix.c:18
BOOL g_fRandomizeMessages
Definition: settings.c:21
HDC hdc
Definition: main.c:9
#define msg(x)
Definition: auth_time.c:54
int MessageSpeed()
Definition: message.c:141
#define MSGSPEED_MIN
Definition: globals.h:28
void DrawMatrixMessage(MATRIX *matrix, MATRIX_MESSAGE *msg, HDC hdc)
Definition: message.c:97
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by DecodeMatrix().

◆ DrawMatrixMessage()

void DrawMatrixMessage ( MATRIX matrix,
MATRIX_MESSAGE msg,
HDC  hdc 
)

Definition at line 97 of file message.c.

98 {
99  int x, y;
100 
101  for(x = 0; x < msg->width; x++)
102  for(y = 0; y < msg->height; y++)
103  if((msg->message[x][y] & 0x8000) &&
104  (msg->message[x][y] & 0x00FF))
105  {
107  }
108 }
GLuint GLenum matrix
Definition: glext.h:9407
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define MAX_INTENSITY
Definition: globals.h:15
#define GLYPH_WIDTH
Definition: globals.h:17
HDC hdc
Definition: main.c:9
void DrawGlyph(MATRIX *matrix, HDC hdc, int xpos, int ypos, GLYPH glyph)
Definition: matrix.c:167
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define msg(x)
Definition: auth_time.c:54
GLYPH RandomGlyph(int intensity)
Definition: matrix.c:45
#define GLYPH_HEIGHT
Definition: globals.h:18

Referenced by DoMatrixMessage().

◆ InitMatrixMessage()

MATRIX_MESSAGE* InitMatrixMessage ( HWND  hwnd,
int  width,
int  height 
)

Definition at line 229 of file message.c.

230 {
232 
233  if((msg = malloc(sizeof(MATRIX_MESSAGE))) == 0)
234  return 0;
235 
237 
238  msg->msgindex = 0;
239  msg->width = min(width, MAXMSG_WIDTH);
240  msg->height = min(height, MAXMSG_HEIGHT);
241  msg->counter = -(int)(crc_rand() % MSGSPEED_MIN + MSGSPEED_MIN);
242 
243  msg->random_reg1 = (WORD)GetTickCount();
244 
246 
248 
249  return msg;
250 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
GLint GLint GLsizei width
Definition: gl.h:1546
TCHAR g_szMessages[MAX_MESSAGES][MAXMSG_LENGTH]
Definition: settings.c:13
void ClearMatrixMessage(MATRIX_MESSAGE *msg)
Definition: message.c:129
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
TCHAR g_szFontName[]
Definition: settings.c:16
#define MAXMSG_WIDTH
Definition: globals.h:23
void SetMatrixMessage(MATRIX_MESSAGE *msg, HFONT hFont, TCHAR *text)
Definition: message.c:38
#define MAXMSG_HEIGHT
Definition: globals.h:24
int crc_rand()
Definition: matrix.c:18
int g_nFontSize
Definition: settings.c:20
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL g_fFontBold
Definition: settings.c:22
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define min(a, b)
Definition: monoChain.cc:55
void SetMessageFont(HWND hwnd, TCHAR *szFontName, int nPointSize, BOOL fBold)
Definition: message.c:201
#define msg(x)
Definition: auth_time.c:54
#define malloc
Definition: debug_ros.c:4
#define MSGSPEED_MIN
Definition: globals.h:28
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by CreateMatrix().

◆ MessageSpeed()

int MessageSpeed ( )

Definition at line 141 of file message.c.

142 {
144 }
#define MSGSPEED_MAX
Definition: globals.h:27
int g_nMessageSpeed
Definition: settings.c:15
#define MSGSPEED_MIN
Definition: globals.h:28

Referenced by DoMatrixMessage().

◆ RevealMatrixMessage()

void RevealMatrixMessage ( MATRIX_MESSAGE msg,
int  amount 
)

Definition at line 113 of file message.c.

114 {
115  while(amount--)
116  {
117  int pos;
118 
119  msg->random_reg1 = crc_msgrand(msg->random_reg1);
120  pos = msg->random_reg1 & 0xffff;
121 
122  msg->message[pos / 256][pos % 256] |= GLYPH_REDRAW;
123  }
124 }
WORD crc_msgrand(WORD reg)
Definition: message.c:23
#define GLYPH_REDRAW
Definition: matrix.h:20
#define msg(x)
Definition: auth_time.c:54

Referenced by DoMatrixMessage().

◆ SetMatrixMessage()

void SetMatrixMessage ( MATRIX_MESSAGE msg,
HFONT  hFont,
TCHAR text 
)

Definition at line 38 of file message.c.

39 {
40  HDC hdc;
41  RECT rect;
42  int x, y;
43 
44  HDC hdcMessage;
45  HBITMAP hbmMessage;
46 
47  HANDLE hOldFont, hOldBmp;
48 
49  //
50  // Create a monochrome off-screen buffer
51  //
52  hdc = GetDC(NULL);
53 
54  hdcMessage = CreateCompatibleDC(hdc);
55  hbmMessage = CreateBitmap(MAXMSG_WIDTH, MAXMSG_HEIGHT, 1, 1, 0);
56  hOldBmp = SelectObject(hdcMessage, hbmMessage);
57 
58  ReleaseDC(NULL, hdc);
59 
60  //
61  // Draw text into bitmap
62  //
63  SetRect(&rect, 0, 0, msg->width, MAXMSG_HEIGHT);
64  FillRect(hdcMessage, &rect, GetStockObject(WHITE_BRUSH));
65 
66  hOldFont = SelectObject(hdcMessage, g_hFont);
68 
69  OffsetRect(&rect, (msg->width-(rect.right-rect.left))/2, (msg->height-(rect.bottom-rect.top))/2);
70  DrawText(hdcMessage, text, -1, &rect, DT_CENTER|DT_VCENTER|DT_WORDBREAK);
71 
72  //
73  // Convert bitmap into an array of cells for easy drawing
74  //
75  for(y = 0; y < msg->height; y++)
76  {
77  for(x = 0; x < msg->width; x++)
78  {
79  msg->message[x][y] = GetPixel(hdcMessage, x, y) ? 0 : 1;
80  }
81  }
82 
83  //
84  // Cleanup
85  //
86  SelectObject(hdcMessage, hOldFont);
87  SelectObject(hdcMessage, hOldBmp);
88 
89  DeleteDC(hdcMessage);
90  DeleteObject(hbmMessage);
91 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
HDC WINAPI GetDC(_In_opt_ HWND)
const WCHAR * text
Definition: package.c:1827
#define DT_WORDBREAK
Definition: winuser.h:544
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define WHITE_BRUSH
Definition: wingdi.h:901
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
& rect
Definition: startmenu.cpp:1413
#define DrawText
Definition: winuser.h:5672
#define MAXMSG_WIDTH
Definition: globals.h:23
#define DT_CALCRECT
Definition: winuser.h:526
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define MAXMSG_HEIGHT
Definition: globals.h:24
smooth NULL
Definition: ftsmooth.c:416
#define DT_VCENTER
Definition: winuser.h:543
HDC hdc
Definition: main.c:9
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI DeleteDC(_In_ HDC)
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
HFONT g_hFont
Definition: settings.c:25
#define msg(x)
Definition: auth_time.c:54
#define DT_CENTER
Definition: winuser.h:527
static HBITMAP
Definition: button.c:44
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)

Referenced by DoMatrixMessage(), and InitMatrixMessage().

◆ SetMessageFont()

void SetMessageFont ( HWND  hwnd,
TCHAR szFontName,
int  nPointSize,
BOOL  fBold 
)

Definition at line 201 of file message.c.

202 {
203  int lfHeight;
204  HDC hdc;
205  HFONT hFont;
206 
207  hdc = GetDC(hwnd);
208 
209  lfHeight = -MulDiv(nPointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
210 
211  ReleaseDC(hwnd, hdc);
212 
213  hFont = CreateFont(lfHeight, 0, 0, 0, fBold ? FW_BOLD: FW_NORMAL, 0, 0, 0,
215  ANTIALIASED_QUALITY, DEFAULT_PITCH, szFontName);
216 
217  if(hFont != 0)
218  {
219  if(g_hFont != 0)
221 
222  g_hFont = hFont;
223  }
224 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ANTIALIASED_QUALITY
Definition: wingdi.h:439
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HFONT hFont
Definition: main.c:53
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateFont
Definition: wingdi.h:4438
#define DEFAULT_PITCH
Definition: wingdi.h:442
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
HDC hdc
Definition: main.c:9
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define FW_BOLD
Definition: wingdi.h:377
HFONT g_hFont
Definition: settings.c:25
#define FW_NORMAL
Definition: wingdi.h:372
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define LOGPIXELSY
Definition: wingdi.h:718
#define ANSI_CHARSET
Definition: wingdi.h:382
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

Referenced by InitMatrixMessage(), and UpdatePreview().