void updateClock(TimeStructType *watch, uint8_t mode){ uint16_t col; uint8_t tmode=0; /* Deleting the hands related to the old time */ drawTime(oldwatch.hours, oldwatch.minutes, oldwatch.seconds, oldwatch.tenths, Black, 1); /* tickSeconds(watch); */ /* Draw the new hands */ switch (mode) { case 1: col = White; break; case 2: col = Red; break; case 3: col = Green; break; case 4: col = Blue; tmode=1; } drawTime(watch->hours, watch->minutes, watch->seconds, watch->tenths, col, tmode); drawCenter(); copyTime(&oldwatch, watch); }
void TimeScene::drawTimeLog(const QModelIndex &index) { Task* task = _model->task(index); std::vector<TaskLog*> *logs = NULL; int groupLevel = 2; if (task != NULL) { logs = task->logs(true); groupLevel = (task->childCount() > 0) ? 1 : 2; } else { Project* project = _model->project(index); if (project != NULL) { logs = project->logs(); groupLevel = 0; } } if ((logs != NULL) && (logs->size() != 0)) { std::sort(logs->begin(), logs->end(), compareTaskLog); DateTime* currentDay = NULL; DTime currentTime(0); for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) { TaskLog* log = *iter; DateTime logDate(log->start->getYear(), log->start->getMonth(), log->start->getDay()); if (currentDay == NULL) { currentDay = new DateTime(logDate.toDouble()); currentTime = (*log->end - *log->start); } else if (logDate == *currentDay) { currentTime = currentTime + (*log->end - *log->start); } else { drawTime(*currentDay, currentTime, index, groupLevel); if (currentDay != NULL) { delete(currentDay); currentDay = NULL; } currentDay = new DateTime(logDate.toDouble()); currentTime = (*log->end - *log->start); } } if (currentTime.totalSecs() != 0) { drawTime(*currentDay, currentTime, index, groupLevel); } if (currentDay != NULL) { delete(currentDay); currentDay = NULL; } } _currentY += sizeHint(index).height(); if (!isCollapsed(index)) { for (int x = 0; x < _model->rowCount(index); x++) { QModelIndex child = _model->index(x, 0, index); if (child.isValid()) { drawIndex(child); } } } if (logs != NULL) { delete(logs); } }
static void drawStrings(void) { if (gameMode == GAME_MODE_PUZZLE) { /* Step */ arduboy.drawBitmap(0, 0, imgLabelStep, 15, 5, WHITE); drawNumber(0, 6, step); /* Issue */ arduboy.drawBitmap(0, 53, imgLabelIssue, 17, 5, WHITE); drawNumber(0, 59, issue + 1); } else { /* Score */ arduboy.drawBitmap(0, 6, imgLabelScore, 19, 5, WHITE); arduboy.setTextColor(WHITE); drawNumber(0, 0, score); arduboy.setTextColor(WHITE, WHITE); if (gameMode == GAME_MODE_ENDLESS) { /* Level */ arduboy.drawBitmap(0, 53, imgLabelLevel, 19, 5, WHITE); if (blinkLevelFrames / 4 % 2 == 0) drawNumber(0, 59, level); } else { /* Time */ arduboy.drawBitmap(0, 53, imgLabelTime, 13, 5, WHITE); drawTime(0, 59, FRAMES_3MINUTES - gameFrames); } } if (state == STATE_PLAYING && blinkChainFrames > 0) { /* Chain */ arduboy.drawBitmap(111, 53, imgLabelChain, 17, 5, WHITE); if (blinkChainFrames / 4 % 2 == 0) { int16_t x = 111 + ((currentChain < 100) + (currentChain < 10)) * 6; drawNumber(x, 59, currentChain); } } }
void violet::HUD::draw(GameState* gameState, Player* player) { float health = player->getHealth() / player->MaxHealth(); float experience = (float) (player->Xp - player->LastLevelXp) / (player->NextLevelXp - player->LastLevelXp); VideoMode screen = m_videoManager->getVideoMode(); drawMessages(); drawTime(gameState); applyEffects(health, player->LevelPoints); int bottomBasePoint = m_videoManager->getVideoMode().Height - m_videoManager->RegularText->getIndent() * 2; drawHealth(health, bottomBasePoint); drawExperience(experience, player->LevelPoints, bottomBasePoint); drawInventory(player); if (gameState->Lost && !gameState->Paused) drawEndGameScreen(gameState, player->Xp); if (!gameState->Lost) if (Info != "") m_videoManager->RegularText->draw(Info.c_str(), m_videoManager->getVideoMode().Width / 2, m_videoManager->RegularText->getIndent(), TextManager::CENTER, TextManager::TOP); if (gameState->Paused) m_videoManager->RegularText->draw(_("PAUSE"), screen.Width / 2, screen.Height / 2, TextManager::CENTER, TextManager::MIDDLE); }
int main(int argc, char *argv[]) { //>>>>>>>>>> carregament da codepage <<<<<<<<<< load_char_table(codepage); //>>>>>>>>>> init kbc <<<<<<<<< Bool mouse_detected = kbc_init(0); //>>>>>>>>>> init kbd <<<<<<<<<< kbd_init(); //>>>>>>>>>> init mouse <<<<<<<<<< if (mouse_detected == true) mouse_init((int) 0); //>>>>>>>>>> init rtc <<<<<<<<<< rtc_init(); drawDate(); drawTime(); drawCounter(); //>>>>>>>>>> init timer <<<<<<<<<< timer0_init(); timer_init(TIMER_2, LSBMSB | MODE3); //################# menu_start(); //################# //>>>>>>>>>> restore kbd isr <<<<<<<<<< restore_keyboard_isr(); //>>>>>>>>>> restore mouse isr <<<<<<<<<< if (mouse_detected == true) restore_mouse_isr(); //>>>>>>>>>> restore rtc isr <<<<<<<<<< restore_rtc_isr(); //>>>>>>>>>> init timer isr <<<<<<<<<< restore_timer0(); return 0; }
void RenderPreview::drawPreview() { if (_renderingInProgress) return; // avoid double-entering this method util::ScopedBoolLock lock(_renderingInProgress); glViewport(0, 0, _previewWidth, _previewHeight); // Set up the render and clear the drawing area in any case glDepthMask(GL_TRUE); glClearColor(0.3f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set up the camera Matrix4 projection = getProjectionMatrix(0.1f, 10000, PREVIEW_FOV, _previewWidth, _previewHeight); // Keep the modelview matrix in the volumetest class up to date _volumeTest.setModelView(getModelViewMatrix()); _volumeTest.setProjection(projection); // Pre-Render event if (!onPreRender()) { // a return value of false means to cancel rendering drawTime(); return; } // Front-end render phase, collect OpenGLRenderable objects from the scene getScene()->foreachVisibleNodeInVolume(_volumeTest, _sceneWalker); RenderStateFlags flags = getRenderFlagsFill(); // Launch the back end rendering _renderSystem->render(flags, _volumeTest.GetModelview(), projection); // Give subclasses an opportunity to render their own on-screen stuff onPostRender(); // Draw the render time drawTime(); }
void Clock::paint(Graphics& g) { if (isRecording) { g.fillAll(Colour(255,0,0)); } else { g.fillAll(Colour(58,58,58)); } drawTime(g); }
void updateWindow() { long ticks; drawBackground(); drawAllItems(); drawExampleName(); drawSourceImage(); ticks = drawFXImage(); drawTime( ticks ); }
static void drawSinglePlayerStats(void) { int lh; lh = (3 * FR_CharHeight('0')) / 2; // Line height. DGL_Enable(DGL_TEXTURE_2D); DGL_Color4f(1, 1, 1, 1); FR_SetFont(FID(GF_FONTB)); FR_LoadDefaultAttrib(); FR_SetColorAndAlpha(defFontRGB2[CR], defFontRGB2[CG], defFontRGB2[CB], 1); WI_DrawPatchXY3(pKills, Hu_ChoosePatchReplacement(cfg.inludePatchReplaceMode, pKills), SP_STATSX, SP_STATSY, ALIGN_TOPLEFT, 0, DTF_NO_TYPEIN); WI_DrawPatchXY3(pItems, Hu_ChoosePatchReplacement(cfg.inludePatchReplaceMode, pItems), SP_STATSX, SP_STATSY + lh, ALIGN_TOPLEFT, 0, DTF_NO_TYPEIN); WI_DrawPatchXY3(pSecretSP, Hu_ChoosePatchReplacement(cfg.inludePatchReplaceMode, pSecretSP), SP_STATSX, SP_STATSY + 2 * lh, ALIGN_TOPLEFT, 0, DTF_NO_TYPEIN); WI_DrawPatchXY3(pTime, Hu_ChoosePatchReplacement(cfg.inludePatchReplaceMode, pTime), SP_TIMEX, SP_TIMEY, ALIGN_TOPLEFT, 0, DTF_NO_TYPEIN); if(wbs->parTime != -1) { WI_DrawPatchXY3(pPar, Hu_ChoosePatchReplacement(cfg.inludePatchReplaceMode, pPar), SCREENWIDTH / 2 + SP_TIMEX, SP_TIMEY, ALIGN_TOPLEFT, 0, DTF_NO_TYPEIN); } FR_SetFont(FID(GF_SMALL)); drawPercent(SCREENWIDTH - SP_STATSX, SP_STATSY, cntKills[0]); drawPercent(SCREENWIDTH - SP_STATSX, SP_STATSY + lh, cntItems[0]); drawPercent(SCREENWIDTH - SP_STATSX, SP_STATSY + 2 * lh, cntSecret[0]); if(cntTime >= 0) { drawTime(SCREENWIDTH / 2 - SP_TIMEX, SP_TIMEY, cntTime / TICRATE); } if(wbs->parTime != -1 && cntPar >= 0) { drawTime(SCREENWIDTH - SP_TIMEX, SP_TIMEY, cntPar / TICRATE); } DGL_Disable(DGL_TEXTURE_2D); }
/** * drawGameObjects * Zeichnen aller im Spiel vorhandenen Objekte und Anzeigen. */ void GameWorld::drawGameObjects() { drawPoints(); drawTime(); drawLives(); drawCombo(); if(gameState->getStatus() == STOPPED) { drawEndPoints(); } for (std::list<GameObject*>::iterator it=GameObjectList.begin(); it!=GameObjectList.end(); ++it) { (*it)->draw(); } }
bool ItemView::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { Gtk::Allocation allocation = get_allocation(); int width = allocation.get_width(); int height = allocation.get_height(); //draw bottom shadow cr->set_source_rgb(0.9, 0.9, 0.9); cr->paint(); //make room for content height -= 1; //update clear notification button layout updateClearNotificationButtonLayout(width, height); fontTime.set_size(FONT_SIZE * PANGO_SCALE); fontTitle.set_size(FONT_SIZE * PANGO_SCALE); fontDescription.set_size(FONT_SIZE_SMALL * PANGO_SCALE); cr->set_antialias(Cairo::ANTIALIAS_NONE); drawBackground(cr, width, height); cr->set_antialias(Cairo::ANTIALIAS_DEFAULT); //draw objects drawTime(cr, width, height); drawTitle(cr, width, height); drawDescription(cr, width, height); drawReminderIcon(cr, width, height); //update buttons layout according to selection state and description position updateButtonsLayout(width, height, rectDescription.get_y(), rectDescription.get_height()); //draw buttons drawButtons(cr, width, height); return true; }
static void drawResult(void) { /* Score */ arduboy.setTextSize(2); int dx = 59; uint32_t dummy = score; while (dummy >= 10) { dummy /= 10; dx -= 6; } drawNumber(dx, 0, score); arduboy.setTextSize(1); /* Each die */ uint32_t totalErasedDice = 0; for (int i = 0; i < 6; i++) { int dx = (i % 3) * 30 + 37; int dy = (i / 3) * 6 + 38; arduboy.drawBitmap(dx, dy, imgMiniDie[i], 5, 5, WHITE); drawNumber(dx + 6, dy, min(erasedEachDie[i], EACHDIE_MAX)); totalErasedDice += erasedEachDie[i]; } /* Others */ arduboy.printEx(1, 14, F("LEVEL")); arduboy.printEx(1, 20, F("MAX CHAIN")); arduboy.printEx(1, 26, F("PLAY TIME")); arduboy.printEx(1, 32, F("ERASED DICE")); if (gameMode == GAME_MODE_ENDLESS) { drawNumber(73, 14, level); } else { arduboy.printEx(73, 14, F("--")); } drawNumber(73, 20, maxChain); drawTime(73, 26, gameFrames); drawNumber(73, 32, totalErasedDice); }
void handleMouseDown( Point point ) { int i; long ticks; int itemNum = -1; Rect tempRect1, tempRect2; for (i = 0; i < numBItems; i++) if (PtInRect( point, &bItem[i].rect )) { if (i == settings.bItem - 1) return; drawItem( bItem[settings.bItem - 1].rect.left, bItem[settings.bItem - 1].rect.top, &bItem[settings.bItem - 1].label, true, false ); drawItem( bItem[i].rect.left, bItem[i].rect.top, &bItem[i].label, true, true ); itemNum = 0; settings.bItem = i + 1; break; } if (gCurrentExample / 10 == transferID || gCurrentExample / 10 == customID) for (i = 0; i < numTItems && itemNum == -1; i++) if (PtInRect( point, &tItem[i].rect )) { if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) { drawItem( tItem[settings.tItem - 1].rect.left, tItem[settings.tItem - 1].rect.top, &tItem[settings.tItem - 1].label, true, false ); drawItem( tItem[i].rect.left, tItem[i].rect.top, &tItem[i].label, true, true ); itemNum = i + 1; settings.tItem = itemNum; } break; } if (gCurrentExample / 10 == arithmeticID || gCurrentExample / 10 == customID) for (i = 0; i < numAItems && itemNum == -1; i++) if (PtInRect( point, &aItem[i].rect )) { if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) { drawItem( aItem[settings.aItem - 1].rect.left, aItem[settings.aItem - 1].rect.top, &aItem[settings.aItem - 1].label, true, false ); drawItem( aItem[i].rect.left, aItem[i].rect.top, &aItem[i].label, true, true ); itemNum = i + 1; settings.aItem = itemNum; } break; } if (gCurrentExample / 10 == colorizationID || gCurrentExample / 10 == customID) for (i = 0; i < numCItems && itemNum == -1; i++) if (PtInRect( point, &cItem[i].rect )) { if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) { drawItem( cItem[settings.cItem - 1].rect.left, cItem[settings.cItem - 1].rect.top, &cItem[settings.cItem - 1].label, true, false ); drawItem( cItem[i].rect.left, cItem[i].rect.top, &cItem[i].label, true, true ); itemNum = i + 1; settings.cItem = itemNum; } break; } if (gCurrentExample / 10 == ditherID || gCurrentExample / 10 == customID) for (i = 0; i < numDItems && itemNum == -1; i++) if (PtInRect( point, &dItem[i].rect )) { if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) { drawItem( dItem[settings.dItem - 1].rect.left, dItem[settings.dItem - 1].rect.top, &dItem[settings.dItem - 1].label, true, false ); drawItem( dItem[i].rect.left, dItem[i].rect.top, &dItem[i].label, true, true ); itemNum = i + 1; settings.dItem = itemNum; } break; } if (gCurrentExample / 10 == searchProcID || gCurrentExample / 10 == customID) for (i = 0; i < numMItems && itemNum == -1; i++) if (PtInRect( point, &mItem[i].rect )) { if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) { drawItem( mItem[settings.mItem - 1].rect.left, mItem[settings.mItem - 1].rect.top, &mItem[settings.mItem - 1].label, true, false ); drawItem( mItem[i].rect.left, mItem[i].rect.top, &mItem[i].label, true, true ); itemNum = i + 1; settings.mItem = itemNum; } break; } if (gCurrentExample / 10 == paintBucketID) { Rect rect; void paintBucketExample(); /*SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37, (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );*/ GetPortBounds(GetWindowPort(gWindow), &tempRect1); GetPortBounds(gGWorld, &tempRect2); SetRect( &rect, tempRect1.right - tempRect2.right - 20, 37, tempRect1.right - 20, 37 + tempRect2.bottom); paintBucketExample( &rect, 0, point ); } if (itemNum != -1) { if (itemNum == 0) { drawSourceImage(); ticks = drawFXImage(); drawTime( ticks ); } else { if (gCurrentExample / 10 == customID) itemNum = gCurrentExample; else itemNum = ((gCurrentExample / 10) * 10) + itemNum; if (itemNum != gCurrentExample || itemNum / 10 == customID) { gCurrentExample = itemNum; drawSourceImage(); ticks = drawFXImage(); drawTime( ticks ); } } } }
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); }
int main(int argc, char *argv[]) { int n, show_days = 0, but_stat = 0, microtm = 0, running = 0, force = 0; time_t last_time = 0; char *geometry = NULL, *xdisplay = NULL; static int signals[] = {SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0}; XEvent Event; assert(sizeof(char) == 1); umask(077); do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force); path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1; if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) { fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } snprintf(dirName, path_len, "%s/.wmwork", getenv("HOME")); snprintf(logname, path_len, "%s/worklog", dirName); snprintf(lockname, path_len, "%s/.#LOCK", dirName); if (chdir(dirName) < 0) { if (errno == ENOENT) { if (mkdir(dirName, 0777)) { fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } compat(); } else { fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } } for (n = 0; signals[n]; n++) { if (signal(signals[n], handler) == SIG_ERR) { fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); } } make_lock(force); atexit(at_exit); read_log(); current = first; initXwindow(xdisplay); createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64); openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL); AddMouseRegion(BUT_START, 5, 48, 22, 58); AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58); AddMouseRegion(BUT_STOP, 41, 48, 58, 58); AddMouseRegion(BUT_PREV, 5, 33, 16, 43); AddMouseRegion(BUT_NEXT, 47, 33, 58, 43); drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); while (1) { last_time = now.tv_sec; gettimeofday(&now, &tz); if (running) { current->time += now.tv_sec - last_time; sess_time += now.tv_sec - last_time; microtm = now.tv_usec; drawTime(current->time, sess_time, microtm, show_days, running); RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); case ButtonPress: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (n) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonDown(n); break; } but_stat = n; RedrawWindow(); break; case ButtonRelease: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (but_stat) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonUp(but_stat); break; } if (but_stat && n == but_stat) { switch (but_stat) { case BUT_START: running = 1; break; case BUT_PAUSE: running = 0; break; case BUT_STOP: write_log(); write_record(); running = 0; sess_time = 0; break; case BUT_PREV: if (!running && sess_time == 0) current = current->prev; break; case BUT_NEXT: if (!running && sess_time == 0) current = current->next; break; } drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); } RedrawWindow(); but_stat = 0; break; } } usleep(50000L); if (do_exit) exit(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); }
void PlaylistItemDelegate::paintBody(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const bool isSelected = option.state & QStyle::State_Selected; if (isSelected) QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter); 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(); // get the video metadata const Video *video = index.data(VideoRole).value<VideoPointer>().data(); // draw the "current track" highlight underneath the text if (isActive && !isSelected) paintActiveOverlay(painter, option, line); // thumb const QPixmap &thumb = video->getThumbnail(); if (!thumb.isNull()) { painter->drawPixmap(0, 0, thumb); if (video->getDuration() > 0) drawTime(painter, video->getFormattedDuration(), line); } const bool thumbsOnly = line.width() <= thumbWidth + 60; const bool isHovered = index.data(HoveredItemRole).toBool(); // play icon overlayed on the thumb bool needPlayIcon = isActive; if (thumbsOnly) needPlayIcon = needPlayIcon && !isHovered; if (needPlayIcon) painter->drawPixmap(0, 0, playIcon); if (!thumbsOnly) { // text color if (isSelected) painter->setPen(QPen(option.palette.highlightedText(), 0)); else painter->setPen(QPen(option.palette.text(), 0)); // title QStringRef title(&video->getTitle()); QString elidedTitle = video->getTitle(); static const int titleFlags = Qt::AlignTop | Qt::TextWordWrap; QRect textBox = line.adjusted(padding + thumbWidth, padding, -padding, 0); textBox = painter->boundingRect(textBox, titleFlags, elidedTitle); while (textBox.height() > 55 && elidedTitle.length() > 10) { #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) title = title.left(title.length() - 1); #elif QT_VERSION < QT_VERSION_CHECK(5, 8, 0) title.truncate(title.length() - 1); #else title.chop(1); #endif elidedTitle = title.trimmed() + QStringLiteral("…"); textBox = painter->boundingRect(textBox, titleFlags, elidedTitle); } painter->drawText(textBox, titleFlags, elidedTitle); painter->setFont(smallerFont); painter->setOpacity(.5); QFontMetrics fontMetrics = painter->fontMetrics(); static const int flags = Qt::AlignLeft | Qt::AlignTop; // published date const QString &published = video->getFormattedPublished(); QSize textSize(fontMetrics.size(Qt::TextSingleLine, published)); QPoint textPoint(padding + thumbWidth, padding * 2 + textBox.height()); textBox = QRect(textPoint, textSize); painter->drawText(textBox, flags, published); bool elided = false; // author if (!listView || listView->isClickableAuthors()) { bool authorHovered = isHovered && index.data(AuthorHoveredRole).toBool(); painter->save(); painter->setFont(smallerBoldFont); if (!isSelected) { if (authorHovered) painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0)); } const QString &author = video->getChannelTitle(); textPoint.setX(textBox.right() + padding); textSize = QSize(painter->fontMetrics().size(Qt::TextSingleLine, author)); textBox = QRect(textPoint, textSize); authorRects.insert(index.row(), textBox); if (textBox.right() > line.width() - padding) { textBox.setRight(line.width()); elided = drawElidedText(painter, textBox, flags, author); } else { painter->drawText(textBox, flags, author); } painter->restore(); } // view count if (video->getViewCount() > 0) { const QString &viewCount = video->getFormattedViewCount(); textPoint.setX(textBox.right() + padding); textSize = QSize(fontMetrics.size(Qt::TextSingleLine, viewCount)); if (elided || textPoint.x() + textSize.width() > line.width() - padding) { textPoint.setX(thumbWidth + padding); textPoint.setY(textPoint.y() + textSize.height() + padding); } textBox = QRect(textPoint, textSize); if (textBox.bottom() <= line.height()) { painter->drawText(textBox, flags, viewCount); } } if (downloadInfo) { const QString &def = VideoDefinition::forCode(video->getDefinitionCode()).getName(); textPoint.setX(textBox.right() + padding); textSize = QSize(fontMetrics.size(Qt::TextSingleLine, def)); textBox = QRect(textPoint, textSize); painter->drawText(textBox, flags, def); } } else { // thumbs only if (isHovered) { painter->setFont(smallerFont); painter->setPen(Qt::white); QStringRef title(&video->getTitle()); QString elidedTitle = video->getTitle(); static const int titleFlags = Qt::AlignTop | Qt::TextWordWrap; QRect textBox(padding, padding, thumbWidth - padding * 2, thumbHeight - padding * 2); textBox = painter->boundingRect(textBox, titleFlags, elidedTitle); while (textBox.height() > 55 && elidedTitle.length() > 10) { #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) title = title.left(title.length() - 1); #elif QT_VERSION < QT_VERSION_CHECK(5, 8, 0) title.truncate(title.length() - 1); #else title.chop(1); #endif elidedTitle = title.trimmed() + QStringLiteral("…"); textBox = painter->boundingRect(textBox, titleFlags, elidedTitle); } painter->fillRect(QRect(0, 0, thumbWidth, textBox.height() + padding * 2), QColor(0, 0, 0, 128)); painter->drawText(textBox, titleFlags, elidedTitle); } } painter->restore(); if (downloadInfo) paintDownloadInfo(painter, option, index); }