Ejemplo n.º 1
0
// Function to append a string to another.
void appendString(char* text, char* app){
	int size1 = stringSize(text);
	int size2 = stringSize(app);
	int i;
	for(i=size1;i<size1+size2;i++){
		text[i] = app[i-size1];
	}
	text[size1+size2] = '\0';
	return;
}
Ejemplo n.º 2
0
char* concatSansStringH(char* str1, char* str2) {
	/****
	*	Retourne la concatenation str1 et str2, la plus petite est en premier
	*	SANS <string.h>
	*****/

	// Test de longueur pour savoir quel str sera en premier
	if (stringSize(str1) > stringSize(str2)) {
		return stringConcat(str2,str1);
	} else {
		return stringConcat(str1,str2);
	}
}
Ejemplo n.º 3
0
//Compares two strings to see if they are equal
//Returns 1 if equal, 0 if they are not equal
int compareText(char* text1, char* text2){
	int size1 = stringSize(text1);
	int size2 = stringSize(text2);
		
	if(size1 == size2){
		int i;
		for(i=0;i<size1;i++){
			if(text1[i] != text2[i]){
				//Different characters
				return 0;
			}
		}
		//Identical strings
		return 1;
	}
	//Different sizes
	return 0;
}
Ejemplo n.º 4
0
char* stringConcat(char* str1, char* str2) {
	/****
	*	Retourne la concatenation de str1 et str2
	*****/

	char* tmp = malloc(24*sizeof(char));
	int k=0 ,i=0, o=0;

	// On remplit tmp avec str1 puis str2, i et o sont leurs iterrateurs
	for (k=0; k < (stringSize(str1)+stringSize(str2)); k++) {
		if (k < stringSize(str1)) {
			tmp[k] = str1[i];
			i++;
		} else {
			tmp[k] = str2[o];
			o++;
		}
	}

	return tmp;
}
Ejemplo n.º 5
0
void doStringUp(FILE *stream) {
  float x, y;
  int a, c, tmp;
  gdPoint size, point;

  x = getFloat(stream);
  y = getFloat(stream);
  c = getColor(getNumber(stream));
  a = getNumber(stream);
  getLine(stream);

  // compute anchor position here

  size = stringSize(buffer, currentFontIdx);
  point.x = viewx(x);
  point.y = viewy(y);
  point = stringAnchor(point, size, a, 1);
  gdImageStringUp(image, currentFont, point.x, point.y, buffer, c);
}
Ejemplo n.º 6
0
void doString(FILE *stream) {
  float x, y;
  int a, c;
  gdPoint size, point;

  x = getFloat(stream);
  y = getFloat(stream);
  c = getColor(getNumber(stream));
  a = getNumber(stream);
  getLine(stream);

  if (currentFontIdx == 0) {
    gdImageStringFT(image, NULL, c, currentFontFT, 10.0, 0.0, viewx(x), viewy(y), buffer);
  } else {
    size = stringSize(buffer, currentFontIdx);
    point.x = viewx(x);
    point.y = viewy(y);
    point = stringAnchor(point, size, a, 0);
    gdImageString(image, currentFont, point.x, point.y, buffer, c);
  }
}
Ejemplo n.º 7
0
void ViewEngineering::ButtonGadget::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );
		Font * pFont = windowStyle()->font();
		ASSERT( pFont );

		// display damage percentage
		String status;
		status.format( "%d%%", int( m_rGadget->damageRatioInv() * 100) );

		SizeInt stringSize( pFont->size( status ) );
		PointInt stringPos( window.m_Right - stringSize.width, window.top );
		Font::push( pDisplay, pFont, stringPos, status, YELLOW );

		// display the damage bar
		if ( m_rGadget->damage() > 0 )
		{
			if ( fmod( activeTime(), 1.0f ) < 0.5f )		// make the bar blink
			{
				float damage = m_rGadget->damageRatioInv();
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
				PrimitiveWindow::push( pDisplay, bar, DAMAGE_BAR_UV, barColor );
			}
		}

		// display white blinking box around gadget currently at the top of the queue
		NounShip * pShip = WidgetCast<NounShip>( m_rGadget->parentBody() );
		if ( pShip != NULL && pShip->repairCount() > 0 && pShip->repair( 0 ) == m_rGadget && fmod( activeTime(), 1.0f ) < 0.5f )
			renderGlow( context );
	}
}
Ejemplo n.º 8
0
void CBitmapFont::renderString(const std::string &str, F32 x, F32 y, F32 size){
	if(!mTextures.size())
		makeFont();
	F32 w,h;
	stringSize(str, &w, &h);
	if(x != -9999.0 && y != -9999.0){
		pen.x = x;
		pen.y = y + 16;
	}
	F32 startx = 0;

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for(S32 i = 0 ; i < str.size() ; i++){
        if(str[i] == '\n'){
            pen.x = startx;
            pen.y += getFontSize() * 64.0 * 1.4 / dpi;
        } else
            renderChar(str[i]);
	}
	glDisable(GL_BLEND);
}
Ejemplo n.º 9
0
int main() {
  stringSize();
  compareStrings();
}
Ejemplo n.º 10
0
void PrettyItemDelegate::paintBody( QPainter* painter,
                                    const QStyleOptionViewItem& option,
                                    const QModelIndex& index ) const {

    painter->save();
    painter->translate( option.rect.topLeft() );


    QRectF line(0, 0, option.rect.width(), option.rect.height());
    if (downloadInfo) line.setWidth(line.width() / 2);
    painter->setClipRect(line);

    const bool isActive = index.data( ActiveTrackRole ).toBool();
    const bool isSelected = option.state & QStyle::State_Selected;

    // draw the "current track" highlight underneath the text
    if (isActive && !isSelected) {
        paintActiveOverlay(painter, line.x(), line.y(), line.width(), line.height());
    }

    // get the video metadata
    const VideoPointer videoPointer = index.data( VideoRole ).value<VideoPointer>();
    const Video *video = videoPointer.data();

    // thumb
    if (!video->thumbnail().isNull()) {
        painter->drawImage(QRect(0, 0, THUMB_WIDTH, THUMB_HEIGHT), video->thumbnail());

        // play icon overlayed on the thumb
        if (isActive)
            paintPlayIcon(painter);

        // time
        QString timeString;
        int duration = video->duration();
        if ( duration > 3600 )
            timeString = QTime().addSecs(duration).toString("h:mm:ss");
        else
            timeString = QTime().addSecs(duration).toString("m:ss");
        drawTime(painter, timeString, line);

    }

    if (isActive) painter->setFont(boldFont);

    // text color
    if (isSelected)
        painter->setPen(QPen(option.palette.brush(QPalette::HighlightedText), 0));
    else
        painter->setPen(QPen(option.palette.brush(QPalette::Text), 0));

    // title
    QString videoTitle = video->title();
    QRectF textBox = line.adjusted(PADDING+THUMB_WIDTH, PADDING, -2 * PADDING, -PADDING);
    textBox = painter->boundingRect( textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, videoTitle);
    painter->drawText(textBox, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, videoTitle);

    painter->setFont(smallerFont);

    // published date
    QString publishedString = video->published().date().toString(Qt::DefaultLocaleShortDate);
    QSizeF stringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, publishedString ) );
    QPointF textLoc(PADDING+THUMB_WIDTH, PADDING*2 + textBox.height());
    QRectF publishedTextBox(textLoc , stringSize);
    painter->drawText(publishedTextBox, Qt::AlignLeft | Qt::AlignTop, publishedString);

    // author
    bool authorHovered = false;
    bool authorPressed = false;
    const bool isHovered = index.data(HoveredItemRole).toBool();
    if (isHovered) {
        authorHovered = index.data(AuthorHoveredRole).toBool();
        authorPressed = index.data(AuthorPressedRole).toBool();
    }

    painter->save();
    painter->setFont(smallerBoldFont);
    if (!isSelected) {
        if (authorHovered)
            painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0));
        else
            painter->setPen(QPen(option.palette.brush(QPalette::Mid), 0));
    }
    QString authorString = video->author();
    textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
    stringSize = QSizeF(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) );
    QRectF authorTextBox(textLoc , stringSize);
    authorRects.insert(index.row(), authorTextBox.toRect());
    painter->drawText(authorTextBox, Qt::AlignLeft | Qt::AlignTop, authorString);
    painter->restore();

    // view count
    if (video->viewCount() >= 0) {
        painter->save();
        QLocale locale;
        QString viewCountString = tr("%1 views").arg(locale.toString(video->viewCount()));
        textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
        stringSize = QSizeF(QFontMetrics(painter->font()).size( Qt::TextSingleLine, viewCountString ) );
        QRectF viewCountTextBox(textLoc , stringSize);
        painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, viewCountString);
        painter->restore();
    }

    if (downloadInfo) {
        painter->save();
        QString definitionString = VideoDefinition::getDefinitionName(video->getDefinitionCode());
        textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
        stringSize = QSizeF(QFontMetrics(painter->font()).size( Qt::TextSingleLine, definitionString ) );
        QRectF viewCountTextBox(textLoc , stringSize);
        painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, definitionString);
        painter->restore();
    }

    /*
    QLinearGradient myGradient;
    QPen myPen;
    QFont myFont;
    QPointF baseline(authorTextBox.x(), authorTextBox.y() + authorTextBox.height());
    QPainterPath myPath;
    myPath.addText(baseline, boldFont, authorString);
    painter->setBrush(palette.color(QPalette::WindowText));
    painter->setPen(palette.color(QPalette::Dark));
    painter->setRenderHints (QPainter::Antialiasing, true);
    painter->drawPath(myPath);
    */

    // separator
    painter->setClipping(false);
    painter->setPen(option.palette.color(QPalette::Midlight));
    painter->drawLine(THUMB_WIDTH, THUMB_HEIGHT, option.rect.width(), THUMB_HEIGHT);
    if (!video->thumbnail().isNull())
        painter->setPen(Qt::black);
    painter->drawLine(0, THUMB_HEIGHT, THUMB_WIDTH-1, THUMB_HEIGHT);

    painter->restore();

    if (downloadInfo) paintDownloadInfo(painter, option, index);

}
Ejemplo n.º 11
0
//Send email with attachment photo taken from Webcam
void *emailPhotoFunc(void *arg){
	struct commandStructure *command = (commandStructure *) arg;
	char cmd[PARS_SIZE];
	//char message[PARS_SIZE];
	char emailAddress[PARS_SIZE];
	char emailSubject[PARS_SIZE];
	char emailMessage[PARS_SIZE];	
	char streamerCommand[100];
	time_t now = time(NULL);
	int status;
		
	//Copy command info locally
	strcpy(cmd,(const char*) command->cmd);
	strcpy(emailAddress,(const char*) command->par[0]);
	strcpy(emailSubject,(const char*) command->par[1]);
	strcpy(emailMessage,(const char*) command->par[2]);
	
	if(DEBUG){
		printf("============================\nIn emailPhoto thread:\n");
		printf("cmd: %s\n",cmd);
		printf("email: %s\n",emailAddress);
		printf("subject: %s\n",emailSubject);
		printf("message: %s\n",emailMessage);
		printf("time: %s",ctime(&now));
	}	
	
	//Create streamer command to take a photo from webcam
	strcpy(streamerCommand, "streamer -q -w 0 -t 5 -j 85 -c /dev/video1 -s 640x480 -o ~/capture00.jpeg");
	status = system(streamerCommand);
	if(status == -1){
		printf("==Error: Could not take picture from webcam. Command %s\n",streamerCommand);
		pthread_exit(NULL);
	}else{
		printf("==Picture taken successfully!\n");
	}
	
	//Email command
	char* email[stringSize(emailAddress)+5];
	char* subject[stringSize(emailSubject)+10];
	
	clearString((char*)email);
	appendString((char*)email,"To: ");
	appendString((char*)email,emailAddress);
	appendString((char*)email,"\n");				
	
	clearString((char*)subject);
	appendString((char*)subject,"Subject: ");
	appendString((char*)subject,emailSubject);
	appendString((char*)subject,"\n");

	//1. Open email file
	FILE* fp;
	fp = fopen("/home/udooer/mail.txt","w+");
	
	//2. Write To, From, Subject and Contents
	fputs((char*)email,fp);
	fputs("From: [email protected]\n",fp);
	fputs((char*)subject,fp);
	fputs("\n",fp);
	fprintf(fp,"%s\n",emailMessage);
	fprintf(fp,"%s\n",ctime(&now));
	fputs("\n",fp);
	fputs("Message sent by Udoo Neo.\n",fp);
	fputs("=========================\n",fp);
	fputs("\n",fp);

	//3. Close file
	fclose(fp);
	
	char mpackCommand[100];
	strcpy(mpackCommand,"mpack -s \"");
	strcat(mpackCommand,(const char*) emailSubject);
	strcat(mpackCommand, "\" -d ~/mail.txt ~/capture04.jpeg ");
	strcat(mpackCommand, emailAddress);
	if(DEBUG) printf("Command to execute: %s\n",mpackCommand);
	status = system(mpackCommand);
	if(status == -1){ 
		printf("==Error: could not send email\n");
	}else{
		//printf("  ============================\nIn emailPhoto thread:\n");
		printf("==Email sent successfully! on %s",ctime(&now));
		//printf("  ============================\n");
	}	

	//printf("%s\n",ctime(&now));
	pthread_exit(NULL);	
}
Ejemplo n.º 12
0
void ButtonGadget::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	// get a pointer to our gadget
	NounGadget * pGadget = m_Gadget;
	if ( pGadget != NULL )
	{
		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );
		WindowStyle * pStyle = windowStyle();
		ASSERT( pStyle );
		Font * pFont = pStyle->font();
		ASSERT( pFont );

		// display bar if gadget has delay before usabled
		int delay = pGadget->usableWhen();
		if ( delay > 0 )
		{
			if ( (pDoc->tick() % 10) < 6 )		// make the bar blink
			{
				RectInt bar( window.left, window.top, 
					window.right - ((window.width() * delay) / 100), window.top + 16 );

				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::ADDITIVE );
				PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, Color(0,0,255,255) );
			}			
		}

		// draw the gadget icon
		Material * pIcon = pGadget->icon();
		if ( pIcon != NULL )
		{
			RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) );

			Material::push( context, pIcon );
			PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, m_IconColor );
		}

		// display any gadget status text
		WideString sStatus( pGadget->status() );
		if ( sStatus.length() > 0 )
		{
			SizeInt stringSize( pFont->size( sStatus ) );
			Font::push( pDisplay, pFont, PointInt( window.m_Right - stringSize.width, window.top ), sStatus, YELLOW );
		}

		// display hotkey in lower-left corner of button
		CharString sHotKey;
		if ( pGadget->hotkey() != 0 && pGadget->hotkey() != HK_SPACE )
			sHotKey += keyText( Keyboard::unmap( pGadget->hotkey() ) );

		if ( m_Gadget->group() != 0 )
			sHotKey += CharString().format(" %c", m_Gadget->group() );

		if ( WidgetCast<GadgetBeamWeapon>( pGadget ) && ((GadgetBeamWeapon *)pGadget)->pointDefense() )
			sHotKey += " PD";

		if ( sHotKey.length() > 0 )
		{
			WideString sWide = sHotKey;
			SizeInt stringSize( pFont->size( sWide ) );

			Font::push( pDisplay, pFont, PointInt( window.m_Right - stringSize.width, window.m_Bottom - stringSize.height ), 
				sWide, YELLOW );
		}

		// display the damage bar
		if ( pGadget->damage() > 0 )
		{
			if ( (pDoc->tick() % 10) < 6 )		// make the bar blink
			{
				float damage = pGadget->damageRatioInv();
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
				PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, barColor );
			}
		}

		// blink a white border if this is the current target
		if ( pDoc->target() == m_Gadget && (pDoc->tick() % 10) < 6 )
			renderGlow( context );
	}
}
Ejemplo n.º 13
0
// Function to clear a string.
void clearString(char* text){
	int size = stringSize(text);
	//printf("Clearing %d characters\n",size);
	memset(text,0,size);
}
Ejemplo n.º 14
0
void ButtonContact::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	DisplayDevice * pDisplay = context.display();
	ASSERT( pDisplay );
	GameDocument * pDoc = (GameDocument *)document();
	ASSERT( pDoc );
	NounShip * pShip = pDoc->ship();
	if (! pShip )
		return;
	WindowStyle * pStyle = windowStyle();
	ASSERT( pStyle );
	Font * pFont = pStyle->font();
	ASSERT( pFont );

	// get a pointer to our gadget
	Noun * pContact = m_Noun;
	if (! pContact )
		return;

	RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 16, 16 ) );

	Color iconColor( YELLOW );
	if ( pShip->isFriend( pContact ) )
		iconColor = GREEN;
	else if ( pShip->isEnemy( pContact ) )
		iconColor = RED;

	// draw the gadget icon
	Material::push( context, m_Icon );
	PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, iconColor );

	if ( WidgetCast<NounShip>( pContact ) 
		&& ((NounShip *)pContact)->canOrder( pShip ) )
	{
		Material::push( context, WidgetCast<Material>( resource("team") ) );
		iconBox += PointInt( 16, 0 );
		PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, WHITE );
	}
	else if ( m_IsObjective )
	{
		Material::push( context, WidgetCast<Material>( resource("objective") ) );
		iconBox += PointInt( 16, 0 );
		PrimitiveWindow::push( pDisplay, iconBox, WINDOW_UV, WHITE );
	}

	// display status text
	CharString sStatus = pContact->displayName( false );
	if ( m_HotKey != 0 )
		sStatus = CharString().format("%c:%s", m_HotKey, sStatus );
	if ( sStatus.length() > 0 )
	{
		SizeInt stringSize( pFont->size( sStatus ) );
		// make sure the text fits on the label
		while( stringSize.width > (BUTTON_WIDTH - 5 ) )
		{
			// remove the right most character and check the width again
			sStatus.left( sStatus.length() - 1 );
			stringSize = pFont->size( sStatus );
		}

		PointInt stringPos( window.m_Right - stringSize.width, window.m_Bottom - stringSize.height );
		Font::push( pDisplay, pFont, stringPos, sStatus, m_bGroupLeader ? YELLOW : (m_bGroupPending ? GREY : WHITE) );
	}

	// display the damage bar
	if ( WidgetCast<NounShip>( pContact ) )
	{
		if ( ((NounShip *)pContact)->damage() > 0 )
		{
			float damage = ((NounShip *)pContact)->damageRatioInv();
			RectInt bar( window.m_Left, window.m_Bottom + 1, 
				window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );

			Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
			PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
			PrimitiveWindow::push( pDisplay, bar, WINDOW_UV, barColor );
		}
	}

	// render additional border if this contact is our current target
	if ( pDoc->rootTarget() == m_Noun && (pDoc->tick() % 10) < 6 )
		renderGlow( context );
}
Ejemplo n.º 15
0
void PlaylistItemDelegate::paintBody( QPainter* painter,
                                      const QStyleOptionViewItem& option,
                                      const QModelIndex& index ) const {
    painter->save();
    painter->translate( option.rect.topLeft() );

    QRect line(0, 0, option.rect.width(), option.rect.height());
    if (downloadInfo) line.setWidth(line.width() / 2);

    const bool isActive = index.data( ActiveTrackRole ).toBool();
    const bool isSelected = option.state & QStyle::State_Selected;

    // draw the "current track" highlight underneath the text
    if (isActive && !isSelected)
        paintActiveOverlay(painter, line);

    // get the video metadata
    const VideoPointer videoPointer = index.data( VideoRole ).value<VideoPointer>();
    const Video *video = videoPointer.data();

    // thumb
    painter->drawPixmap(0, 0, video->thumbnail());

    // play icon overlayed on the thumb
    if (isActive)
        painter->drawPixmap(playIcon.rect(), playIcon);

    // time
    if (video->duration() > 0)
        drawTime(painter, video->formattedDuration(), line);

    // separator
    painter->setPen(option.palette.color(QPalette::Midlight));
    painter->drawLine(THUMB_WIDTH, THUMB_HEIGHT, option.rect.width(), THUMB_HEIGHT);
    if (!video->thumbnail().isNull())
        painter->setPen(Qt::black);
    painter->drawLine(0, THUMB_HEIGHT, THUMB_WIDTH-1, THUMB_HEIGHT);

    if (line.width() > THUMB_WIDTH + 60) {

        // if (isActive) painter->setFont(boldFont);

        // text color
        if (isSelected)
            painter->setPen(QPen(option.palette.highlightedText(), 0));
        else
            painter->setPen(QPen(option.palette.text(), 0));

        // title
        QString videoTitle = video->title();
        QString v = videoTitle;
        const int flags = Qt::AlignTop | Qt::TextWordWrap;
        QRect textBox = line.adjusted(PADDING+THUMB_WIDTH, PADDING, 0, 0);
        textBox = painter->boundingRect(textBox, flags, v);
        while (textBox.height() > 55 && v.length() > 10) {
            videoTitle.truncate(videoTitle.length() - 1);
            v = videoTitle;
            v = v.trimmed().append("...");
            textBox = painter->boundingRect(textBox, flags, v);
        }
        painter->drawText(textBox, flags, v);

        painter->setFont(smallerFont);

        // published date
        QString publishedString = video->published().date().toString(Qt::DefaultLocaleShortDate);
        QSize stringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, publishedString ) );
        QPoint textLoc(PADDING+THUMB_WIDTH, PADDING*2 + textBox.height());
        QRect publishedTextBox(textLoc , stringSize);
        painter->drawText(publishedTextBox, Qt::AlignLeft | Qt::AlignTop, publishedString);

        if (line.width() > publishedTextBox.x() + publishedTextBox.width()*2) {

            // author
            bool authorHovered = false;
            bool authorPressed = false;
            const bool isHovered = index.data(HoveredItemRole).toBool();
            if (isHovered) {
                authorHovered = index.data(AuthorHoveredRole).toBool();
                authorPressed = index.data(AuthorPressedRole).toBool();
            }

            painter->save();
            painter->setFont(smallerBoldFont);
            if (!isSelected) {
                if (authorHovered)
                    painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0));
                else
                    painter->setOpacity(.5);
            }
            QString authorString = video->channelTitle();
            textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
            stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) );
            QRect authorTextBox(textLoc , stringSize);
            authorRects.insert(index.row(), authorTextBox);
            painter->drawText(authorTextBox, Qt::AlignLeft | Qt::AlignTop, authorString);
            painter->restore();

            if (line.width() > authorTextBox.x() + 50) {

                // view count
                if (video->viewCount() >= 0) {
                    QLocale locale;
                    QString viewCountString = tr("%1 views").arg(locale.toString(video->viewCount()));
                    textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
                    stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, viewCountString ) );
                    QRect viewCountTextBox(textLoc , stringSize);
                    painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, viewCountString);
                }

                if (downloadInfo) {
                    const QString definitionString = VideoDefinition::getDefinitionFor(video->getDefinitionCode()).getName();
                    textLoc.setX(textLoc.x() + stringSize.width() + PADDING);
                    stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, definitionString ) );
                    QRect viewCountTextBox(textLoc , stringSize);
                    painter->drawText(viewCountTextBox, Qt::AlignLeft | Qt::AlignBottom, definitionString);
                }

            }

        }

    } else {

        const bool isHovered = index.data(HoveredItemRole).toBool();
        if (!isActive && isHovered) {
            painter->setFont(smallerFont);
            painter->setPen(Qt::white);
            QString videoTitle = video->title();
            QString v = videoTitle;
            const int flags = Qt::AlignTop | Qt::TextWordWrap;
            QRect textBox(PADDING, PADDING, THUMB_WIDTH - PADDING*2, THUMB_HEIGHT - PADDING*2);
            textBox = painter->boundingRect(textBox, flags, v);
            while (textBox.height() > THUMB_HEIGHT && v.length() > 10) {
                videoTitle.truncate(videoTitle.length() - 1);
                v = videoTitle;
                v = v.trimmed().append("...");
                textBox = painter->boundingRect(textBox, flags, v);
            }
            painter->fillRect(QRect(0, 0, THUMB_WIDTH, textBox.height() + PADDING*2), QColor(0, 0, 0, 128));
            painter->drawText(textBox, flags, v);
        }

    }

    painter->restore();

    if (downloadInfo) paintDownloadInfo(painter, option, index);

}
Ejemplo n.º 16
0
void ButtonCargo::onRender( RenderContext & context, const RectInt & window )
{
	WindowButton::onRender( context, window );

	if ( enabled() )
	{
		Noun * pCargo = m_Cargo;
		ASSERT( pCargo );

		// display white box around cargo if current target
		GameDocument * pDoc = (GameDocument *)document();
		ASSERT( pDoc );

		if ( pDoc->target() == pCargo && (pDoc->tick() % 10) < 6 )
			renderGlow( context );

		if ( WidgetCast<CargoEnhancement>( pCargo ) )
		{
			// show the durability if an enhancement..
			CargoEnhancement * pCargoEnh = (CargoEnhancement *)pCargo;

			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			NounEnhancement * pEnhancement = pCargoEnh->enhancement();
			if ( pEnhancement != NULL )
			{
				int nMaxDamage = pEnhancement->maxDamage();
				if ( nMaxDamage > 0 )
				{
					WideString sQuantity;
					sQuantity.format( "%d/%d", nMaxDamage - pCargoEnh->damage(), nMaxDamage );

					SizeInt stringSize( pFont->size( sQuantity ) );
					PointInt stringPos( window.m_Right - stringSize.width, window.top );
					Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );
				}
			}

			if ( ((CargoEnhancement *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounCargo>( pCargo ) )
		{
			// draw the quantity if cargo
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sQuantity;
			sQuantity.format( "%d", ((NounCargo *)pCargo)->quantity() );

			SizeInt stringSize( pFont->size( sQuantity ) );
			PointInt stringPos( window.m_Right - stringSize.width, window.top );
			Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );

			if ( ((NounCargo *)pCargo)->quantity() <= 0 )
				destroy();
		}
		else if ( WidgetCast<NounUnit>( pCargo ) )
		{
			NounUnit * pUnit = (NounUnit *)pCargo;

			// draw the unit health on the button
			Font * pFont = windowStyle()->font();
			ASSERT( pFont );

			WideString sHealth;
			sHealth.format( "%d%%", 100 - ((pUnit->damage() * 100) / pUnit->maxDamage()) );

			PointInt ptHealth( window.right - pFont->size( sHealth ).width, window.top );
			Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );

			// display damage bar
			if ( pUnit->damage() > 0 )
			{
				float damage = 1.0f - (pUnit->damage() / pUnit->maxDamage());
				RectInt bar( window.m_Left, window.m_Bottom + 1, 
					window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
				RectFloat barUV(0,0,1,1);

				Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
				PrimitiveMaterial::push( context.display(), PrimitiveMaterial::NONE );
				PrimitiveWindow::push( context.display(), bar, barUV, barColor );
			}
		}
	}
}
Ejemplo n.º 17
0
//Email function to be called in a "detached" thread
void *emailFunc(void *arg){
	struct commandStructure *command = (commandStructure *) arg;
	char cmd[PARS_SIZE];
	char emailAddress[PARS_SIZE];
	char emailSubject[PARS_SIZE];
	char emailMessage[PARS_SIZE];
	time_t now = time(NULL);
	
	if(DEBUG){
		printf("============================\nIn email thread:\n");
		printf("cmd: %s\n",cmd);
		printf("email: %s\n",emailAddress);
		printf("subject: %s\n",emailSubject);
		printf("message: %s\n",emailMessage);
		printf("time: %s",ctime(&now));
	}	
	
	//Copy command info locally
	strcpy(cmd,(const char*) command->cmd);
	strcpy(emailAddress,(const char*) command->par[0]);
	strcpy(emailSubject,(const char*) command->par[1]);
	strcpy(emailMessage,(const char*) command->par[2]);

	int status;
	char* email[stringSize(emailAddress)+5];
	char* subject[stringSize(emailSubject)+10];
	
	clearString((char*)email);
	appendString((char*)email,"To: ");
	appendString((char*)email,emailAddress);
	appendString((char*)email,"\n");				
	
	clearString((char*)subject);
	appendString((char*)subject,"Subject: ");
	appendString((char*)subject,emailSubject);
	appendString((char*)subject,"\n");				

	//1. Open email file
	FILE* fp;
	fp = fopen("/home/udooer/mail.txt","w+");
	
	//2. Write To, From, Subject and Contents
	fputs((char*)email,fp);
	fputs("From: [email protected]\n",fp);
	fputs((char*)subject,fp);
	fputs("\n",fp);
	fprintf(fp,"%s\n",emailMessage);
	fprintf(fp,"%s\n",ctime(&now));
	fputs("\n",fp);
	fputs("Message sent by Udoo Neo.\n",fp);
	fputs("=========================\n",fp);
	fputs("\n",fp);

	//3. Close file
	fclose(fp);
	status = system("cat ~/mail.txt");
	if(status == -1) printf("Error: could not execute command\n");
	
	//4. send email
	char ssmtpCommand[40];
	strcpy(ssmtpCommand, "ssmtp ");
	appendString((char*) ssmtpCommand, emailAddress);
	strcat(ssmtpCommand, " < ~/mail.txt");
	printf("Command to execute: %s\n",ssmtpCommand);
	status = system(ssmtpCommand);
	if(status == -1){ 
		printf("Error: could not send email\n");
	}else{
		printf("Email sent successfully! on %s\n",ctime(&now));
	}
	
	pthread_exit(NULL);
}