3 void * IS_XGetDisplay();
9 const char * textString = "Let it snow!";
10 define backgroundColor = Color { 10, 0, 60 };
12 class Snowing : Window
15 background = backgroundColor;
19 borderStyle = sizable;
24 font = { "Comic Sans MS", 40, true };
25 useSharedMemory = true;
27 ColorAlpha * screen, * screenBuffer;
33 Snowing() { RandomSeed((uint)(GetTime() * 100000)); ((GuiApplication)__thisModule).timerResolution = 60; }
46 void OnRedraw(Surface surface)
48 Bitmap bitmap = ((LFBDisplay)display.driverData).bitmap;
50 if(buffer.width != bitmap.width || buffer.height != bitmap.height)
53 int len = strlen(textString);
54 stride = bitmap.stride;
55 buffer.Allocate(null, bitmap.width, bitmap.height, stride, pixelFormat888, false);
56 surface.TextExtent(textString, strlen(textString), &tw, &th);
60 screen = (ColorAlpha*)bitmap.picture + (surface.offset.y * stride) + surface.offset.x;
61 screenBuffer = (ColorAlpha*)buffer.picture + (surface.offset.y * stride) + surface.offset.x;
62 surface.background = backgroundColor;
63 surface.Area(0,0, w-1, h-1);
64 surface.WriteText((clientSize.w - tw)/2, (clientSize.h - th)/2, textString, len);
67 XSync(IS_XGetDisplay()); // TODO: Need an API for this...
70 memcpy(buffer.picture, bitmap.picture, buffer.sizeBytes);
77 for(y = lastLine; y >= 0; y--)
79 int offset = y * stride;
80 bool isLastLine = true;
81 for(x = 0; x < w; x++, offset++)
83 if(screen[offset].color == white)
88 if(isLastLine) lastLine = y-1;
90 memcpy(bitmap.picture, buffer.picture, buffer.sizeBytes);
97 for(c = 0; c < NUMFLAKES; c++)
98 screenBuffer[GetRandom(0, w-1)] = white;
100 bool SnowTo(int offset, int add)
103 if(screen[add].color != backgroundColor)
105 screenBuffer[add] = white;
106 screenBuffer[offset] = backgroundColor;
109 void SnowDown(int offset)
111 if(offset < (h-2)*stride + w)
113 bool atLeft = (offset % stride) <= 0;
114 bool atRight = (offset % stride) >= w - 1;
115 switch(GetRandom(0, 2))
118 if(!SnowTo(offset, stride))
120 if(GetRandom(0, 4) == 0)
123 (void)((!atLeft && SnowTo(offset, stride-1)) || (!atRight && SnowTo(offset, stride+1)));
125 (void)((!atRight && SnowTo(offset, stride+1)) || (!atLeft && SnowTo(offset, stride-1)));
129 case 1: (void)((!atLeft && SnowTo(offset, stride-1)) || (GetRandom(0, 4) == 0 && SnowTo(offset, stride)) || (!atRight && SnowTo(offset, stride+1))); break;
130 case 2: (void)((!atRight && SnowTo(offset, stride+1)) || (GetRandom(0, 4) == 0 && SnowTo(offset, stride)) || (!atLeft && SnowTo(offset, stride-1))); break;