1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mfxt-lib-vn

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
autoplaytext.cpp 3.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
魔凤啸天 Отправлено 28.11.2021 11:05 a254763
#include "autoplaytext.hpp"
void AutoPlayText::SetCallback(void(*f)(void*),void* a){
arg=a,callback=f;
}
unsigned char AutoPlayText::Alpha(){
unsigned char a;
SDL_GetTextureAlphaMod(back,&a);
return a;
}
void AutoPlayText::SetAlpha(unsigned char a){
SDL_SetTextureAlphaMod(back,a);
if(_t)SDL_SetTextureAlphaMod(_t,a);
}
void AutoPlayText::AutoPlay(void* g){
auto a=(AutoPlayText*)g;
if(a->pos==a->cache.end()||!a->_enabled)return;
auto& i=a->pos;
auto& r=i->rect;
if(r.w<i->w){
r.w+=4;
return;
}
r.w=i->w;
a->pos++;
}
void AutoPlayText::AutoPlayFast(void* g){
auto a=(AutoPlayText*)g;
if(a->pos==a->cache.end()||!a->_enabled)return;
auto& i=a->pos;
auto& r=i->rect;
if(r.w<i->w){
r.w+=8;
return;
}
r.w=i->w;
a->pos++;
}
bool AutoPlayText::IsFast(){return is_fast;}
void AutoPlayText::Play(){
is_fast=false;
if(task)_belong->RemoveTask(task);
task=_belong->AddTask(AutoPlay,this,1,true,true);
}
void AutoPlayText::PlayFast(){
is_fast=true;
if(task)_belong->RemoveTask(task);
task=_belong->AddTask(AutoPlayFast,this,1,true,true);
}
bool AutoPlayText::Finish(){
return pos==cache.end();
}
void AutoPlayText::Stop(){
_belong->RemoveTask(task);
}
void AutoPlayText::SetText(const vector<TextMod>& text){
_cache=text;
if(_t){
SDL_DestroyTexture(_t);
cache.clear();
}
vector<pair<int,int>> a;
_t=BuildText(text,default_font->_font,a);
cache.resize(a.size());
auto begin=cache.begin();
int y=0;
for(auto& n:a){
begin->w=n.first,begin->h=n.second;
begin->rect={0,y,0,n.second};
y+=n.second;
begin++;
}
pos=cache.begin();
}
void AutoPlayText::SetText(const initializer_list<TextMod>& text){
_cache=text;
if(_t){
SDL_DestroyTexture(_t);
cache.clear();
}
vector<pair<int,int>> a;
_t=BuildText(text,default_font->_font,a);
cache.resize(a.size());
auto begin=cache.begin();
int y=0;
for(auto& n:a){
begin->w=n.first,begin->h=n.second;
begin->rect={0,y,0,n.second};
y+=n.second;
begin++;
}
pos=cache.begin();
}
AutoPlayText::AutoPlayText(Window* win,SDL_Rect& r,const char* back_path,void(*callback)(void*),void* arg):
Control(win),_t(0),task(0),callback(callback),arg(arg){
back=win->renderer->LoadTexture(back_path);
SDL_SetTextureBlendMode(back,SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(back,0);
_area=r;
is_fast=false;
}
AutoPlayText::~AutoPlayText(){
if(_t)SDL_DestroyTexture(_t);
SDL_DestroyTexture(back);
}
SDL_Texture* AutoPlayText::Background(){return back;}
void AutoPlayText::_draw(){
auto r=_belong->renderer;
r->DrawTexture(0,&_area,back);
auto t=_t;
auto x=_area.x+120,y=_area.y+50;
for(auto& n:cache){
auto& _r=n.rect;
SDL_Rect dst={x,y+_r.y,_r.w,_r.h};
r->DrawTexture(&_r,&dst,t);
}
}
void AutoPlayText::_release(int x,int y,int clicks,unsigned char key){
if(key==SDL_BUTTON_RIGHT){
auto end=cache.end();
while(pos!=end){
pos->rect.w=pos->w;
pos++;
}
return;
}
callback(arg);
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mfxt-lib-vn.git
git@api.gitlife.ru:oschina-mirror/mfxt-lib-vn.git
oschina-mirror
mfxt-lib-vn
mfxt-lib-vn
master