![]() |
TX Library Help – Version: 00173a, Revision: 174
|
00001 00002 /* Episode X 00003 00004 RETURN OF TXLIB 00005 00006 War! The Republic of Windows is under 00007 attack of modern graphics libraries. 00008 Programmers of the Galaxy fight against 00009 SFML, SDL, OpenGL and DirectX. 00010 00011 But the more pixels painted, the lesser 00012 their Force. Some programmers think to 00013 switch to Pascal and Python. 00014 00015 Being in utter despair, princess Organa 00016 calls for anybody could help the Graphics 00017 to get back its Force. 00018 00019 A long time ago in a galaxy far, far away 00020 a small library called TXLib heard 00021 this call ... 00022 */ 00023 00024 #include "TXLib.h" 00025 00026 HDC CreateSW (const char* source); 00027 00028 int main() 00029 { 00030 txCreateWindow (GetSystemMetrics (SM_CXSCREEN) / 1.5, GetSystemMetrics (SM_CXSCREEN) / 3.0); 00031 txTextCursor (false); 00032 txBegin(); 00033 00034 HDC sw = CreateSW (__FILE__); 00035 if (!sw) return txMessageBox ("ERROR: File \"" __FILE__ "\" NOT found!"), 1; 00036 00037 if (_access (__FILE__ ".wav", 0) != 0) return txMessageBox ("ERROR: File \"" __FILE__ ".wav\" NOT found!"), 1; 00038 txPlaySound (__FILE__ ".wav"); 00039 txSleep (1000); 00040 00041 POINT scr = txGetExtent(); 00042 POINT sz = txGetExtent (sw); 00043 00044 int posY = ROUND (scr.y * 0.8); 00045 00046 unsigned time0 = GetTickCount(); 00047 00048 txSetFillColor (TX_BLACK); 00049 00050 for (double i = 0; i <= sz.y - posY + scr.y && !GetAsyncKeyState (VK_ESCAPE); i += 0.1) 00051 { 00052 txLock(); 00053 00054 txClear(); 00055 00056 for (int y = 0; y <= posY; y++) 00057 { 00058 double t = 1.0 * y / posY; 00059 00060 int sizeX = ROUND (t * scr.x * 5/6 + scr.x/6); 00061 int destX = (scr.x - sizeX) / 2; 00062 00063 int destY = ROUND (y + scr.y - posY); 00064 int srcY = ROUND ((t+1 - 2 / pow (t+1, 3)) * scr.y + i - scr.y); 00065 00066 int alpha = ROUND (t * 255); 00067 00068 Win32::AlphaBlend (txDC(), destX, destY, sizeX, 3, sw, 0, srcY, sz.x, 7, 00069 BLENDFUNCTION { AC_SRC_OVER, 0, (BYTE) alpha, 0 }); 00070 } 00071 00072 txUnlock(); 00073 00074 txSleep(); 00075 00076 double fps = txGetFPS <50> (); 00077 if (fps <= 0) continue; 00078 00079 static double fixFps = 0; 00080 if (fixFps <= 0) fixFps = (fps >= 5)? fps : 5; 00081 00082 char str [128] = ""; 00083 _tx_snprintf_s (str, sizeof (str), __FILE__ " - Time %.0fs, FPS %.0f", (GetTickCount() - time0) / 1000.0, fps); 00084 SetWindowText (txWindow(), str); 00085 00086 i += 1/fixFps * pow (scr.y, 2.53) / 4E5; 00087 } 00088 00089 txDeleteDC (sw); 00090 } 00091 00092 #include <sys/stat.h> 00093 00094 HDC CreateSW (const char* source) 00095 { 00096 struct stat st = {}; 00097 if (stat (source, &st) != 0) return NULL; 00098 size_t size = (size_t) st.st_size; 00099 00100 char* text = new (std::nothrow) char [size + 1] {}; 00101 if (!text) return NULL; 00102 00103 FILE* f = NULL; 00104 fopen_s (&f, source, "r"); if (!f) { delete[] text; return NULL; } 00105 fread (text, size, 1, f); 00106 fclose (f); 00107 00108 int lines = 1; 00109 for (char* s = strchr (text, '\n'); s; s = strchr (s+1, '\n')) lines++; 00110 00111 POINT scr = txGetExtent(); 00112 POINT font = { scr.x/45, scr.y/10 }; 00113 00114 HDC sw = txCreateCompatibleDC (scr.x, scr.y * 2 + font.y * lines); 00115 POINT sz = txGetExtent (sw); 00116 00117 txSetColor (RGB (235, 180, 60), 1, sw); 00118 txSelectFont ("Lucida Console", font.y, font.x, FW_BOLD, false, false, false, 0, sw); 00119 txDrawText (0, scr.y/1.5, sz.x, sz.y + scr.y, text, 0, sw); 00120 00121 delete[] text; 00122 text = NULL; 00123 00124 return sw; 00125 } 00126 00127 #if !defined (_TX_VER) || (_TX_VER < 0x173a0105) 00128 #error Must use TXLib.h version >= 1.73 and revision >= 105 to compile this. 00129 #error Get up-to-date source from http://storage.ded32.net.ru/Lib/TX/TXUpdate/TXLib.h 00130 #error Or use AutoUpdate from http://sourceforge.net/projects/txlib/files/TXLib/TXLib-Update.rar.exe/download 00131 #endif 00132 00133 /******************************************* 00134 * 00135 * Source (c) Ded, 2017 00136 * May the Source be with you! 00137 * 00138 * Inspired by LucasFilm and Kirill Acharya. 00139 * 00140 * Music theme by (C) John Willams. 00141 * 00142 * :) 00143 * 00144 *******************************************/