void Canvas::paintEvent(QPaintEvent *) { /*if (left_canvas_) { std::cout << "Entering left Canvas::paintEvent" << clock() << std::endl; } else { //std::cout << "Entering right Canvas::paintEvent" << std::endl; }*/ //clock_t t_0 = clock(); QImage canvas_image(size_in_pixels_, size_in_pixels_, QImage::Format_RGB32); canvas_delegate_->canvas_image_width_ = canvas_image.width(); canvas_delegate_->canvas_image_data_ = (QRgb*) canvas_image.bits(); QPainter painter(&canvas_image); painter.setPen(canvas_delegate_->pen_); canvas_delegate_->brush_.setStyle(Qt::SolidPattern); painter.setBrush(canvas_delegate_->brush_); painter.setRenderHint(QPainter::Antialiasing, true); canvas_delegate_->painter_ = &painter; painter.eraseRect(0, 0, size_in_pixels_, size_in_pixels_); canvas_delegate_->paint_event(); QPainter canvas_painter(this); canvas_painter.drawImage(0, 0, canvas_image); /*clock_t t_1 = clock(); if (left_canvas_) { //std::cout << "Left paintEvent in " << (t_1- t_0)*100.0/CLOCKS_PER_SEC << "cs" << std::endl; } else { std::cout << "Right paintEvent in " << (t_1- t_0)*100.0/CLOCKS_PER_SEC << "cs" << std::endl; }*/ //std::cout << "Leaving Canvas::paintEvent" << std::endl; return; }
void BlockAnalyzer::analyze(QPainter& p, const Analyzer::Scope& s, bool new_frame) { // y = 2 3 2 1 0 2 // . . . . # . // . . . # # . // # . # # # # // # # # # # # // // visual aid for how this analyzer works. // y represents the number of blanks // y starts from the top and increases in units of blocks // m_yscale looks similar to: { 0.7, 0.5, 0.25, 0.15, 0.1, 0 } // if it contains 6 elements there are 5 rows in the analyzer if (!new_frame) { p.drawPixmap(0, 0, canvas_); return; } QPainter canvas_painter(&canvas_); Analyzer::interpolate(s, m_scope); // Paint the background canvas_painter.drawPixmap(0, 0, m_background); for (uint y, x = 0; x < m_scope.size(); ++x) { // determine y for (y = 0; m_scope[x] < m_yscale[y]; ++y) ; // this is opposite to what you'd think, higher than y // means the bar is lower than y (physically) if ((float)y > m_store[x]) y = int(m_store[x] += m_step); else m_store[x] = y; // if y is lower than m_fade_pos, then the bar has exceeded the height of // the fadeout // if the fadeout is quite faded now, then display the new one if (y <= m_fade_pos[x] /*|| m_fade_intensity[x] < FADE_SIZE / 3*/) { m_fade_pos[x] = y; m_fade_intensity[x] = FADE_SIZE; } if (m_fade_intensity[x] > 0) { const uint offset = --m_fade_intensity[x]; const uint y = m_y + (m_fade_pos[x] * (HEIGHT + 1)); canvas_painter.drawPixmap(x * (WIDTH + 1), y, m_fade_bars[offset], 0, 0, WIDTH, height() - y); } if (m_fade_intensity[x] == 0) m_fade_pos[x] = m_rows; // REMEMBER: y is a number from 0 to m_rows, 0 means all blocks are glowing, // m_rows means none are canvas_painter.drawPixmap(x * (WIDTH + 1), y * (HEIGHT + 1) + m_y, *bar(), 0, y * (HEIGHT + 1), bar()->width(), bar()->height()); } for (uint x = 0; x < m_store.size(); ++x) canvas_painter.drawPixmap( x * (WIDTH + 1), int(m_store[x]) * (HEIGHT + 1) + m_y, m_topBarPixmap); p.drawPixmap(0, 0, canvas_); }
void BarAnalyzer::analyze(QPainter& p, const Scope& s, bool new_frame) { if (!new_frame) { p.drawPixmap(0, 0, canvas_); return; } // Analyzer::interpolate( s, m_bands ); Scope& v = m_scope; Analyzer::interpolate(s, v); QPainter canvas_painter(&canvas_); canvas_.fill(palette().color(QPalette::Background)); for (uint i = 0, x = 0, y2; i < v.size(); ++i, x += COLUMN_WIDTH + 1) { // assign pre[log10]'d value y2 = uint(v[i] * 256); // 256 will be optimised to a bitshift //no, it's a float y2 = m_lvlMapper[(y2 > 255) ? 255 : y2]; // lvlMapper is array of ints with // values 0 to height() int change = y2 - barVector[i]; // using the best of Markey's, piggz and Max's ideas on the way to shift the // bars // we have the following: // 1. don't adjust shift when doing small up movements // 2. shift large upwards with a bias towards last value // 3. fall downwards at a constant pace /*if ( change > MAX_UP ) //anything too much greater than 2 gives "jitter" //add some dynamics - makes the value slightly closer to what it was last time y2 = ( barVector[i] + MAX_UP ); //y2 = ( barVector[i] * 2 + y2 ) / 3; else*/ if (change < MAX_DOWN) y2 = barVector[i] + MAX_DOWN; if ((int)y2 > roofVector[i]) { roofVector[i] = (int)y2; roofVelocityVector[i] = 1; } // remember where we are barVector[i] = y2; if (m_roofMem[i].size() > NUM_ROOFS) m_roofMem[i].erase(m_roofMem[i].begin()); // blt last n roofs, a.k.a motion blur for (uint c = 0; c < m_roofMem[i].size(); ++c) // bitBlt( m_pComposePixmap, x, m_roofMem[i]->at( c ), m_roofPixmaps[ c ] // ); // bitBlt( canvas(), x, m_roofMem[i][c], &m_pixRoof[ NUM_ROOFS - 1 - c ] // ); canvas_painter.drawPixmap(x, m_roofMem[i][c], m_pixRoof[NUM_ROOFS - 1 - c]); // blt the bar canvas_painter.drawPixmap(x, height() - y2, *gradient(), y2 * COLUMN_WIDTH, height() - y2, COLUMN_WIDTH, y2); /*bitBlt( canvas(), x, height() - y2, gradient(), y2 * COLUMN_WIDTH, height() - y2, COLUMN_WIDTH, y2, Qt::CopyROP );*/ m_roofMem[i].push_back(height() - roofVector[i] - 2); // set roof parameters for the NEXT draw if (roofVelocityVector[i] != 0) { if (roofVelocityVector[i] > 32) // no reason to do == 32 roofVector[i] -= (roofVelocityVector[i] - 32) / 20; // trivial calculation if (roofVector[i] < 0) { roofVector[i] = 0; // not strictly necessary roofVelocityVector[i] = 0; } else ++roofVelocityVector[i]; } } p.drawPixmap(0, 0, canvas_); }