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
|
#define delay(x) _sleep((long unsigned int)x)
struct arg_struct
{
console *consolepointer;
WORD txtcolors=0;
string chrtext;
int x;
int y;
int delay;
};
//static for be used by threads:
void BlinkTexttherad(string text, int x=0, int y=0, int delayMilliSecs=500, WORD textcolors=0)
{
//text position:
COORD ord;
ord.X = x;
ord.Y = y;
//getting the empty string of the text:
int textlength = text.length();
string rub=text;
for(int i=0; i<textlength; i++)
{
rub[i]=' ';
}
//converting the string to char(i need avoid a memory leak):
const char *chrtext=text.c_str();
const char *chrtext2=rub.c_str();
//infinite cycle for blink the text:
CONSOLE_SCREEN_BUFFER_INFO txtcolor;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &txtcolor);
LPDWORD lpNumberOfAttrsWritten=NULL;
WORD lpAttribute[textlength];
FillArray(lpAttribute, textlength, textcolors);
static boolean blnonce=false;
blnonce=!blnonce;
WriteConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE),lpAttribute,textlength,ord,lpNumberOfAttrsWritten);
for(;;)
{
DWORD srect;
WriteConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), chrtext2 ,textlength,ord,&srect);
if(blnonce==true)
delay(280);
else
delay(300);
WriteConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE),chrtext,textlength,ord,&srect);
if(blnonce==true)
{
int dllay=delayMilliSecs-20;
delay(dllay);
}
else
delay(delayMilliSecs);
}
}
static void *multithreadproc(void *pThisArg)
{
arg_struct *pThis = static_cast<arg_struct*>(pThisArg);
int x=pThis->x;
int y=pThis->y;
int delay=pThis->delay;
string text=pThis->chrtext;
pThis->consolepointer->BlinkTexttherad(text,x,y,delay, pThis->txtcolors);
return nullptr;//terminates the thread
}
pthread_t some_thread;
arg_struct args;
void BlinkText(string text, int x=0, int y=0, int delayMilliSecs=500)
{
args.txtcolors=wrdtextbackcolor;
args.chrtext=text;
args.x=x;
args.y=y;
args.delay=delayMilliSecs;
args.consolepointer=this;
pthread_create(&some_thread, nullptr, &console::multithreadproc,static_cast<void*>(&args));
delay(20);
}
|