Ejemplo n.º 1
0
int main(int argc,char* argv[]) {
    MorseTranslator morse;
    SDL_Color txtColor   = {   0,  0,  0 },
              morseColor = { 255,  0,  0 },
              bgColor    = {   0,  0,255 };
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        throw std::runtime_error("SDL init failed");
    }
    screenHandler screen;
    if(TTF_Init() < 0) {
        throw std::runtime_error("TTF init failed");
    }
    ttfQuitter _quitTTF;
    _quitTTF.foo();
    if(!(screen.screen = SDL_SetVideoMode(400,300,32,SDL_SWSURFACE|SDL_RESIZABLE))) {
        throw std::runtime_error("SDL surface init failed");
    }
    SDL_EnableUNICODE(1);

    fontHandler font;
    font.font = TTF_OpenFont("brain.ttf",20);
    SDL_WM_SetCaption("T3: Thought To Text",NULL);
    std::string txt = "";

    Uint32 prevFrameBegin = 0;
    bool running = true;
    while(running) {
        Uint32 frameBegin = SDL_GetTicks();
        if(frameBegin-prevFrameBegin >= MS_PER_FRAME) {
            prevFrameBegin = frameBegin;
            SDL_Event e;
            while(SDL_PollEvent(&e)) {
                switch(e.type) {
                case SDL_QUIT:
                    running = false;
                    break;
                case SDL_VIDEORESIZE:
                    screen.screen = SDL_SetVideoMode(e.resize.w,e.resize.h, 32, SDL_SWSURFACE | SDL_RESIZABLE );
                    break;
                case SDL_KEYDOWN: {
                    std::string s;
                    std::cout << s << std::endl;
                    std::cout.flush();
                    s += (char)e.key.keysym.unicode;
                    morse.add(s);
                }
                break;
                default:
                    break;
                }
            }

            SDL_FillRect(screen.screen,NULL,SDL_MapRGB(screen.screen->format,255,255,255));

            std::cout << morse.text() << "|" << morse.morseLetter() << std::endl;

            int x,y;
            drawTextLines(screen.screen,font.font,0,0,morse.text(),txtColor,&x,&y);
            std::string morseTxt = morse.morseLetter();
            if(morseTxt.empty()) {
                morseTxt = "_";
            }
            drawTextLines(screen.screen,font.font,x,y,morseTxt,morseColor,&x,&y);

            std::vector<std::pair<std::string,std::string> > suggestions = morse.suggestions();
            std::vector<std::string> suggestionLines;
            size_t lineLength = 0;
            for(size_t i=0; i<suggestions.size() && i<10; ++i) {
                size_t length = suggestions[i].first.length() + suggestions[i].second.length()+1;
                if(length > lineLength) {
                    lineLength = length;
                }
            }
            for(size_t i=0; i<suggestions.size() && i<10; ++i) {
                size_t length = suggestions[i].first.length() + suggestions[i].second.length()+1;
                std::string pad = "";
                for(int i=length; i<lineLength; ++i) {
                    pad += " ";
                }
                suggestionLines.push_back(suggestions[i].first+ " " + pad + suggestions[i].second);
            }
            SDL_Surface* morsePrompt = buildWindow(font.font,suggestionLines,txtColor,bgColor);
            if(morsePrompt) {
                if(x+morsePrompt->w >= screen.screen->w) {
                    int height;
                    TTF_SizeText(font.font,morseTxt.c_str(),NULL,&height);
                    y += height;
                    x = 0;
                }
                SDL_Rect windowLoc = { x,y,0,0 };
                SDL_BlitSurface(morsePrompt,NULL,screen.screen,&windowLoc);
                SDL_FreeSurface(morsePrompt);
            }

            SDL_Flip(screen.screen);
            //Uint32 frameEnd = SDL_GetTicks();
            //Uint32 frameTime = frameEnd-frameBegin;
            //std::cout << frameTime << "ms/frame" << std::endl;
            //std::cout.flush();
            //if(frameTime < MS_PER_FRAME) {
            //    SDL_Delay(MS_PER_FRAME-(SDL_GetTicks()-frameBegin));
            //}
        }
        SDL_Delay(1);
    }
    return 0;
}
Ejemplo n.º 2
0
int main(int argc,char* argv[]) {
	EmoEngine engine;
	ExpressionProcessor processor;
    MorseTranslator morse;

    SDL_Color txtColor   = {   0,  0,  0 },
              morseColor = { 255,  0,  0 },
              bgColor    = {   0,255,  0 },
              suggColor  = {   0,  0,255 };
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        throw std::runtime_error("SDL init failed");
    }
    screenHandler screen;
    if(TTF_Init() < 0) {
        throw std::runtime_error("TTF init failed");
    }
    ttfQuitter _quitTTF;
    _quitTTF.foo();
    if(!(screen.screen = SDL_SetVideoMode(400,300,32,SDL_SWSURFACE|SDL_RESIZABLE))) {
        throw std::runtime_error("SDL surface init failed");
    }
    SDL_EnableUNICODE(1);

    fontHandler font;
    font.font = TTF_OpenFont("brain.ttf",20);
    SDL_WM_SetCaption("FTS: Facial Typing System",NULL);
    std::string txt = "";

    std::ofstream eventLog("logs/events.csv",std::ios_base::out|std::ios_base::trunc);

    bool locked = false;

    //morse.add(".--- --- . ");

    std::string morseToAdd = "";

    Uint32 prevFrameBegin = 0;
    bool running = true;
    while(running) {
        processor.processEvents(engine);

        Expression e;
        while(processor.getExpression(e)) {
            eventLog << e.time << "," << e.event << "," << e.power << ","
                     << !!(e.eyeState & Expression::BLINK) << ","
                     << !!(e.eyeState & Expression::LWINK) << ","
                     << !!(e.eyeState & Expression::RWINK) << ","
                     << !!(e.eyeState & Expression::RLOOK) << ","
                     << !!(e.eyeState & Expression::LLOOK) << std::endl;
            morseToAdd += exp2Morse(e);
        }

        Uint32 frameBegin = SDL_GetTicks();
        if(frameBegin-prevFrameBegin >= MS_PER_FRAME) {
            prevFrameBegin = frameBegin;
            SDL_Event e;
            while(SDL_PollEvent(&e)) {
                switch(e.type) {
                case SDL_QUIT:
                    running = false;
                    break;
                case SDL_VIDEORESIZE:
                    screen.screen = SDL_SetVideoMode(e.resize.w,e.resize.h, 32, SDL_SWSURFACE | SDL_RESIZABLE );
                    break;
                //case SDL_KEYDOWN: {
                //        std::string s;
                //        std::cout << s << std::endl;
                //        std::cout.flush();
                //        s += (char)e.key.keysym.unicode;
                //        morse.add(s);
                //    }
                //    break;
#ifdef DEBUG
                case SDL_KEYDOWN: {
                        std::string s = "";
                        s += (char)e.key.keysym.unicode;
                        morseToAdd += s;
                    }
                    break;
#endif
                default:
                    break;
                }
            }

            for(size_t i=0;i<morseToAdd.length();++i) {
                std::string morseText = morseToAdd.substr(i,1);
                if(morseText == "@") {
                    locked = true;
                } else if(locked && morseText == "^") {
                    locked = false;
                } else if(!locked && !morseText.empty()) {
                    morse.add(morseText);
                }
            }
            morseToAdd.clear();

            SDL_FillRect(screen.screen,NULL,SDL_MapRGB(screen.screen->format,255,255,255));

            std::cout << (morse.text()+morse.currWord()) << "|" << morse.morseLetter() << std::endl;

            int x,y;
            drawTextLines(screen.screen,font.font,0,0,(morse.text()+morse.currWord()),txtColor,&x,&y);
            std::string morseTxt = morse.morseLetter();
            if(morseTxt.empty()) {
                morseTxt = "_";
            }
            drawTextLines(screen.screen,font.font,x,y,morseTxt,morseColor,&x,&y);

            std::vector<std::pair<std::string,std::string> > suggestions = morse.morseSuggestions();
            std::vector<std::string> suggestionLines;
            size_t lineLength = 0;
            for(size_t i=0;i<suggestions.size() && i<10;++i) {
                size_t length = suggestions[i].first.length() + suggestions[i].second.length()+1;
                if(length > lineLength) {
                    lineLength = length;
                }
            }
            for(size_t i=0;i<suggestions.size() && i<10;++i) {
                size_t length = suggestions[i].first.length() + suggestions[i].second.length()+1;
                std::string pad = "";
                for(int i=length;i<lineLength;++i) {
                    pad += " ";
                }
                suggestionLines.push_back(suggestions[i].first+ " " + pad + suggestions[i].second);
            }
            SDL_Surface* morsePrompt = buildWindow(font.font,suggestionLines,0,txtColor,bgColor,bgColor);
            int morsePromptH = 0;
            if(morsePrompt) {
                if(x+morsePrompt->w >= screen.screen->w) {
                    int height;
                    TTF_SizeText(font.font,morseTxt.c_str(),NULL,&height);
                    y += height;
                    x = 0;
                }
                SDL_Rect windowLoc = { x,y,0,0 };
                x += morsePrompt->w;
                SDL_BlitSurface(morsePrompt,NULL,screen.screen,&windowLoc);
                SDL_FreeSurface(morsePrompt);
            }
            const std::vector<std::string>& wordSuggs = morse.wordSuggestions();
            SDL_Surface* suggPrompt = buildWindow(font.font,wordSuggs,morse.selectionIndex(),txtColor,suggColor,morseColor);
            if(suggPrompt) {
                if(x+suggPrompt->w >= screen.screen->w) {
                    int height;
                    TTF_SizeText(font.font,morseTxt.c_str(),NULL,&height);
                    y += height;
                    x = 0;
                }
                SDL_Rect windowLoc = { x,y,0,0 };
                x += suggPrompt->w;
                SDL_BlitSurface(suggPrompt,NULL,screen.screen,&windowLoc);
                SDL_FreeSurface(suggPrompt);
            }

            if(locked) {
                std::vector<std::string> lines;
                lines.push_back("Locked. Nod up to unlock");
                SDL_Surface* lockDialog = buildWindow(font.font,lines,0,morseColor,suggColor,suggColor);
                SDL_Rect loc = { (screen.screen->w - lockDialog->w)/2,
                                 (screen.screen->h - lockDialog->h)/2,0,0 };
                SDL_BlitSurface(lockDialog,NULL,screen.screen,&loc);
                SDL_FreeSurface(lockDialog);
            }

            SDL_Flip(screen.screen);
            //Uint32 frameEnd = SDL_GetTicks();
            //Uint32 frameTime = frameEnd-frameBegin;
            //std::cout << frameTime << "ms/frame" << std::endl;
            //std::cout.flush();
            //if(frameTime < MS_PER_FRAME) {
            //    SDL_Delay(MS_PER_FRAME-(SDL_GetTicks()-frameBegin));
            //}
        }
        SDL_Delay(1);
    }
    return 0;





}
Ejemplo n.º 3
0
void eParentalSetup::init_eParentalSetup()
{
	loadSettings();

	parentallock=new eCheckbox(this, parentalpin_enabled, 1);
	parentallock->setText(_("Parental lock"));
	parentallock->move(ePoint(10, yPos()));
	parentallock->resize(eSize(200, widgetHeight()));
	parentallock->setHelpText(_("enable/disable parental lock"));
	CONNECT(parentallock->checked, eParentalSetup::plockChecked );

	changeParentalPin = new eButton(this);
	changeParentalPin->setText(_("change PIN"));
	changeParentalPin->move(ePoint(230, yPos()));
	changeParentalPin->resize(eSize(160, widgetHeight()));
	changeParentalPin->setHelpText(_("change Parental PIN (ok)"));
	changeParentalPin->loadDeco();
	CONNECT(changeParentalPin->selected_id, eParentalSetup::changePin );
	if ( !parentalpin_enabled )
	{
		changeParentalPin->hide();
	}

	nextYPos(35);  
	setuplock=new eCheckbox(this, setuppin_enabled, 1);
	setuplock->setText(_("Setup lock"));
	setuplock->move(ePoint(10, yPos()));
	setuplock->resize(eSize(200, widgetHeight()));
	setuplock->setHelpText(_("enable/disable setup lock"));
	CONNECT(setuplock->checked, eParentalSetup::slockChecked );

	changeSetupPin = new eButton(this);
	changeSetupPin->setText(_("change PIN"));
	changeSetupPin->move( ePoint( 230, yPos()));
	changeSetupPin->resize( eSize(160, widgetHeight()));
	changeSetupPin->setHelpText(_("change Setup PIN (ok)"));
	changeSetupPin->loadDeco();
	CONNECT(changeSetupPin->selected_id, eParentalSetup::changePin );
	if ( !setuppin_enabled )
	{
		changeSetupPin->hide();
	}

	nextYPos(35);  
	pin_timeout_label = new eLabel (this);
	pin_timeout_label->setText (_("Pin timeout"));
	pin_timeout_label->move (ePoint (10, yPos()));
	pin_timeout_label->resize (eSize (370, widgetHeight()));

	pin_timeout = new eNumber (this, 1, 0, 999, 4, &pintimeout, 0, pin_timeout_label);
	pin_timeout->move (ePoint (230, yPos()));
	pin_timeout->resize (eSize (50, widgetHeight()));
	pin_timeout->setHelpText (_("Number of minutes the entered pin is valid. After this timeout you need to re-enter the pin when zapping to protected service (0 to disable)"));
	pin_timeout->loadDeco();

	nextYPos(35);  
	maxpin_errors_label = new eLabel (this);
	maxpin_errors_label->setText (_("Max Pin errors"));
	maxpin_errors_label->move (ePoint (10, yPos()));
	maxpin_errors_label->resize (eSize (370, widgetHeight()));

	maxpin_errors = new eNumber (this, 1, 0, 999, 4, &maxpinerrors, 0, maxpin_errors_label);
	maxpin_errors->move (ePoint (230, yPos()));
	maxpin_errors->resize (eSize (50, widgetHeight()));
	maxpin_errors->setHelpText (_("Maximum number of chances to enter correct pin. When pin is entered wrong for x times the pin validation will be blocked temporarily (0 to disable)"));
	maxpin_errors->loadDeco();

	nextYPos(35);  
	pinerror_block_time_label = new eLabel (this);
	pinerror_block_time_label->setText (_("Pin block timeout"));
	pinerror_block_time_label->move (ePoint (10, yPos()));
	pinerror_block_time_label->resize (eSize (370, widgetHeight()));

	pinerror_block_time = new eNumber (this, 1, 1, 999, 4, &pinerrorblocktime, 0, pinerror_block_time_label);
	pinerror_block_time->move (ePoint (230, yPos()));
	pinerror_block_time->resize (eSize (50, widgetHeight()));
	pinerror_block_time->setHelpText (_("Number of minutes pincode check is disabled when pin validation has failed maximum times."));
	pinerror_block_time->loadDeco();

	nextYPos(35);  
	hidelocked=new eCheckbox(this, shidelocked, 1);
	hidelocked->setText(_("Hide locked services"));
	hidelocked->move(ePoint(10, yPos()));
	hidelocked->resize(eSize(380, widgetHeight()));
	hidelocked->setHelpText(_("don't show locked services in any list"));
	hidelocked->loadDeco();
	CONNECT(hidelocked->checked, eParentalSetup::hidelockChecked );
	if ( !parentalpin_enabled )
	{
		hidelocked->hide();
	}

	/* help text for parental setup */
	setHelpText(_("\tParental Lock\n\n>>> [MENU] >>> [6] Setup >>> [5] Parental Lock\n. . . . . . . . . .\n\n" \
								"Here you can enable and setup Parental Lock. After reboot locked channels will not be available unless unlocked with your PIN code\n" \
								". . . . . . . . . .\n\nUsage:\n\n[UP]/[DOWN]\tSelect Inputfield or Button\n\nParental lock\tToggle Channel access on/off\n\n" \
								"Setup lock\tToggle setup access on/off\n\nChange PIN\tEnter a new PIN code\n\n[GREEN]\tSave Settings and Close Window\n\n" \
								"[EXIT]\tClose window without saving changes"));
								

	buildWindow();

	CONNECT(bOK->selected, eParentalSetup::okPressed);
}
Ejemplo n.º 4
0
EpgConfigDialog::EpgConfigDialog():
	ePLiWindow("EPG Configuration", 400),
	configPath(CONFIGDIR "/dbepg"),
	currentCfg(0)
{
	getConfig();
	/* abort if no valid configurations were found */
	if (configItems.size() == 0)
	{
		eMessageBox("No valid packages found. Please check your configuration.", "Error");
	}

	/* Selector for configuration */
	makeNewLabel(this, "Package", 10, yPos(), 130, widgetHeight());
	eComboBox *cb = new eComboBox(this);
	setWidgetGeom( cb, 190, yPos(), 200, widgetHeight());
	cb->setHelpText("Select the EPG provider");
	cb->loadDeco();
	cb->show();

	eListBoxEntryText *first = 0;
	for (std::map<eString, Config>::const_iterator it=configItems.begin(); it!=configItems.end(); ++it)
	{
		eListBoxEntryText *le= new eListBoxEntryText(*cb, it->second.getName());       //weird syntax....
		if (!first)
		{
			first = le;
		}
	}
	CONNECT(cb->selchanged, EpgConfigDialog::OnItemSelected);

	nextYPos(35);
	makeNewLabel(this, "Time offset", 10, yPos(), 130, widgetHeight());

	cTimeOffset = new eComboBox(this);
	setWidgetGeom( cTimeOffset, 190, yPos(), 200, widgetHeight());
	cTimeOffset->setHelpText("Select the time offset between EPG provider and your time zone");
	cTimeOffset->loadDeco();
	cTimeOffset->show();

	for (int i=-12; i<=12; i++)
	{
		char buf[30];
		sprintf(buf, "%2d hours", i);
		new eListBoxEntryText(*cTimeOffset, buf, (void*) i);       //weird syntax....
	}

	cTimeOffset->setCurrent((void*) 0); //will this work...

//     cTimeOffset = new eNumber(this, 1, -12, 12, 3, 0);
//     setWidgetGeom(cTimeOffset, 130+10+10, yPos(), 100, widgetHeight());
//     cTimeOffset->loadDeco();
//     cTimeOffset->setFlags(eNumber::flagPosNeg);
//     cTimeOffset->show();

	nextYPos(35);
	makeNewLabel(this, "Number of days", 10, yPos(), 130, widgetHeight());
	cNumOfDays = new eNumber( this, 1, 0, 365, 1, 0);
	setWidgetGeom( cNumOfDays, 190, yPos(), 200, widgetHeight() );
	cNumOfDays->setHelpText("Select number of EPG days to retrieve");
	cNumOfDays->loadDeco();
	cNumOfDays->show();

	nextYPos(35);
	makeNewLabel(this, "Cron options:", 10, yPos(), 130, widgetHeight());

//     makeNewLabel(this, "Interval", 10, yPos(), 130, widgetHeight());
//     cInterval =  new eNumber( this, 1, 1, 6, 1, 0);
//     //makeNewNumber(this, 0, 130+10+10, yPos(), 100, widgetHeight(), 6, 1, 7);
//     cInterval->setNumber(interval);
//     setWidgetGeom( cInterval, 150, yPos(), 100, widgetHeight() );
//     cInterval->loadDeco();
//     cInterval->show();

	nextYPos();
	cUseCron = makeNewCheckbox(this, "Use cron", 10, yPos(), 170, widgetHeight());
	cUseCron->setHelpText("Enable cron to retrieve EPG each day automatically");

	makeNewLabel(this, "Update at", 190, yPos(), 130, widgetHeight());
	cStartTime = new eNumber( this, 2, 0, 59, 2, 0, 0);
	setWidgetGeom( cStartTime , 310, yPos(), 80, widgetHeight() );
	cStartTime->setHelpText("Time EPG will be retrieved");
	cStartTime->loadDeco();
	cStartTime->setFlags( eNumber::flagDrawPoints|eNumber::flagFillWithZeros|eNumber::flagTime );
	cStartTime->show();

	nextYPos(40);
	eButton *bt_channels = makeNewButton(this, "Channels",
		10, yPos(), 120, 40, "blue");
	bt_channels->setHelpText("Map channels");
	CONNECT(bt_channels->selected, EpgConfigDialog::OnChannelManagerClicked);

	eButton *bt_retrieve = makeNewButton(this, "Retrieve",
		270, yPos(), 120, 40, "yellow");
	bt_retrieve->setHelpText("Retrieve EPG data");
	CONNECT(bt_retrieve->selected, EpgConfigDialog::OnRetrieveClicked);

	/* Don't send the signal until gui is fully build....*/
	if (first)
	{
		cb->setCurrent(first, true);    //do send a selected message, will update view..
	}

	buildWindow();
	CONNECT(bOK->selected, EpgConfigDialog::OnOkClicked);
}