Exemple #1
0
void KMidChannel::noteOff(int key)
{
    pressed[key]=0;
    QPainter *qpaint=new QPainter(this);
    drawKey(qpaint,key);
    delete qpaint;
};
bool DrawableFactory::addTextFromCSV(const std::string& filename, Resources& res, Scene* scene)
{
    // Fontリソースの読み込み
    FontResourceManager& fr = res.fonts();

    // CSVデータ読み込み
    CSVData data;
    DrawableFactory::loadCSV(filename, data);

    // データを読み出して登録する
    for (auto it = data.begin(); it != data.end(); ++it)
    {
        auto b = (*it);
        // エラー処理
        if (b.size() != 11) {
            printf("Text: ファイルフォーマットエラー\n");
            return false;
        }
        // データの格納
        std::string drawKey(b[0]);
        std::string text(b[2]);
        std::string fontKey(b[8]);
        int layer = std::atoi(b[1].c_str());
        int x =     std::atoi(b[3].c_str());
        int y =     std::atoi(b[4].c_str());
        int red =   std::atoi(b[5].c_str());
        int green = std::atoi(b[6].c_str());
        int blue =  std::atoi(b[7].c_str());
        int alpha = std::atoi(b[9].c_str());
        bool isVisible = (b[10] == "true") ? true : false;

        // エラー処理
        if (b[0] == "" ||
            b[1] == "" ||
            b[8] == "") {
            printf("Text: 未入力が存在します。\n");
            return false;
        }

        // 初期値の処理
        if (b[9] == "") alpha = 255;

        // 生成
        DrawableText* d = new DrawableText();
        d->setFontHandle(fr.get(fontKey));
        d->setPosition(x, y);
        d->setText(text);
        d->setTextColor(red, green, blue);
        d->setAlpha(alpha);
        d->setIsVisible(isVisible);
        scene->addDrawable(drawKey, d, layer);
    
        printf("$$$ Text loaded: %s\n", drawKey.c_str());
    }
    return true;
}
bool DrawableFactory::addImageFromCSV(const std::string& filename, Resources& res, Scene* scene)
{
    ImageResourceManager& ir = res.images();

    // CSVデータ読み込み
    CSVData data;
    DrawableFactory::loadCSV(filename, data);

    // データを読み出して登録する
    for (auto it = data.begin(); it != data.end(); ++it)
    {
        auto b = (*it);
        // エラー処理
        if (b.size() != 11) {
            printf("Image: ファイルフォーマットエラー\n");
            return false;
        }
        // データの格納
        std::string drawKey(b[0]);
        std::string resKey(b[2]);
        int layer = std::atoi(b[1].c_str());
        int x =     std::atoi(b[3].c_str());
        int y =     std::atoi(b[4].c_str());
        int sx =    std::atoi(b[5].c_str());
        int sy =    std::atoi(b[6].c_str());
        int w =     std::atoi(b[7].c_str());
        int h =     std::atoi(b[8].c_str());
        int alpha = std::atoi(b[9].c_str());
        bool isVisible = (b[10] == "true") ? true : false;

        // エラー処理
        if (b[0] == "" ||
            b[1] == "" ||
            b[2] == "") {
            printf("Image: 未入力が存在します。\n");
            return false;
        }

        // 初期値の処理
        if (b[9] == "") alpha = 255;

        // 生成
        DrawableImage* d = new DrawableImage();
        d->setHandle(ir.get(resKey));
        d->setPosition(x, y);
        d->setSrcPosition(sx, sy);
        if (b[7] != "" && b[8] != "") d->setSize(w, h);
        d->setAlpha(alpha);
        d->setIsVisible(isVisible);
        scene->addDrawable(drawKey, d, layer);

        printf("$$$ Image loaded: %s\n", drawKey.c_str());
    }

    return true;
}
Exemple #4
0
 void SurfacePlot::draw(Frame *frame, int dir)
 {
   HLayout hl(*frame,.9);
   Frame f = hl.getFrame(0);
   drawPlot(&f);
   f = hl.getFrame(1);
   BorderLayout bl(f,0,0,0,
       (ylabel.size()?label_style.getPointSize():0)+axis_bottom.label_style.getPointSize()+5);
   f = bl.getFrame(0);
   drawKey(&f); // ,dir);
 }
void KeyboardLayoutWidget::generatePixmap(bool force)
{
    if (!xkb)
        return;

    double ratioX = (double) width() / xkb->geom->width_mm;
    double ratioY = (double) height() / xkb->geom->height_mm;

    ratio = qMin(ratioX, ratioY);

    int w = xkb->geom->width_mm * ratio;
    int h = xkb->geom->height_mm * ratio;
    if (w == image.width() && h == image.height() && !force)
        return;

    image = QImage(w, h, QImage::Format_ARGB32);
    QPainter painter(&image);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.fillRect(image.rect(), Qt::transparent);

    foreach(DrawingItem* item , keyboardItems) {
        if (!xkb)
            return;

        switch (item->type) {
        case KEYBOARD_DRAWING_ITEM_TYPE_INVALID:
            break;

        case KEYBOARD_DRAWING_ITEM_TYPE_KEY:
        case KEYBOARD_DRAWING_ITEM_TYPE_KEY_EXTRA:
            drawKey (&painter, (DrawingKey *) item);
            break;

        case KEYBOARD_DRAWING_ITEM_TYPE_DOODAD:
            drawDoodad (&painter, (Doodad *) item);
            break;
        }
    }

    /*
    QVector<QPointF> vec;
    vec << QPointF(20, 20);
    vec << QPointF(200, 20);
    vec << QPointF(200, 200);
    vec << QPointF(20, 200);

    QBrush brush(Qt::gray);
    painter.setBrush(brush);
    roundedPolygon(&painter, false, 20, vec);*/
    /*image.save("/tmp/test.png", "png");*/
}
Exemple #6
0
void drawKeyboard()
{
	// draw the keyboard here
	drawKey(-18, 6.0, 0.0, 0, 0, '`'); //`
	drawKey(-15, 6.0, 0.0, 1, 0, '1'); //1
	drawKey(-12, 6.0, 0.0, 2, 0, '2'); //2
	drawKey(-9, 6.0, 0.0, 3, 0, '3'); //3
	drawKey(-6, 6.0, 0.0, 4, 0, '4'); //4
	drawKey(-3, 6.0, 0.0, 5, 0, '5'); //5
	drawKey(0, 6.0, 0.0, 6, 0, '6'); //6
	drawKey(3, 6.0, 0.0, 7, 0, '7'); //7
	drawKey(6, 6.0, 0.0, 8, 0, '8'); //8
	drawKey(9, 6.0, 0.0, 9, 0, '9'); //9
	drawKey(12, 6.0, 0.0, 10, 0, '0'); //0
	drawKey(15, 6.0, 0.0, 11, 0, '-'); //-
	drawKey(18, 6.0, 0.0, 12, 0, '='); //=

	drawKey(-15.5, 3.0, 0.0, 0, 1, 'q'); //q
	drawKey(-12.5, 3.0, 0.0, 1, 1, 'w'); //w
	drawKey(-9.5, 3.0, 0.0, 2, 1, 'e'); //e
	drawKey(-6.5, 3.0, 0.0, 3, 1, 'r'); //r
	drawKey(-3.5, 3.0, 0.0, 4, 1, 't'); //t
	drawKey(-.5, 3.0, 0.0, 5, 1, 'y'); //y
	drawKey(2.5, 3.0, 0.0, 6, 1, 'u'); //u
	drawKey(5.5, 3.0, 0.0, 7, 1, 'i'); //i
	drawKey(8.5, 3.0, 0.0, 8, 1, 'o'); //o
	drawKey(11.5, 3.0, 0.0, 9, 1, 'p'); //p
	drawKey(14.5, 3.0, 0.0, 10, 1, '['); //[
	drawKey(17.5, 3.0, 0.0, 11, 1, ']'); //]

	drawKey(-15.0, 0.0, 0.0, 0, 2, 'a'); //a
	drawKey(-12.0, 0.0, 0.0, 1, 2, 's'); //s
	drawKey(-9.0, 0.0, 0.0, 2, 2, 'd'); //d
	drawKey(-6.0, 0.0, 0.0, 3, 2, 'f'); //f
	drawKey(-3.0, 0.0, 0.0, 4, 2, 'g'); //g
	drawKey(0.0, 0.0, 0.0, 5, 2, 'h'); //h
	drawKey(3.0, 0.0, 0.0, 6, 2, 'j'); //j
	drawKey(6.0, 0.0, 0.0, 7, 2, 'k'); //k
	drawKey(9.0, 0.0, 0.0, 8, 2, 'l'); //l
	drawKey(12.0, 0.0, 0.0, 9, 2, ';'); //;
	drawKey(15.0, 0.0, 0.0, 10, 2, '\''); //'

	drawKey(-13.0, -3.0, 0.0, 0, 3, 'z'); //z
	drawKey(-10.0, -3.0, 0.0, 1, 3, 'x'); //x
	drawKey(-7.0, -3.0, 0.0, 2, 3, 'c'); //c
	drawKey(-4.0, -3.0, 0.0, 3, 3, 'v'); //v
	drawKey(-1.0, -3.0, 0.0, 4, 3, 'b'); //b
	drawKey(2.0, -3.0, 0.0, 5, 3, 'n'); //n
	drawKey(5.0, -3.0, 0.0, 6, 3, 'm'); //m
	drawKey(8.0, -3.0, 0.0, 7, 3, ','); //,
	drawKey(11.0, -3.0, 0.0, 8, 3, '.'); //.
	drawKey(14.0, -3.0, 0.0, 9, 3, '/'); ///
}
Exemple #7
0
 /**
  * Draw the Palette key to this frame. dir is the direction from negative
  * to positive for the key.  You probably want to supply a tall, skinny
  * frame for North or South directions and a short and wide frame for East
  * and West directions.
  */
 inline void drawKey(Frame& frame, unsigned int columns = 1)
 {
     drawKey(&frame,columns);
 }
Exemple #8
0
void KMidChannel::drawPressedKeys(QPainter *qpaint)
{
    for (int i=0;i<128;i++)
        if (pressed[i]) drawKey(qpaint,i);
};
void CLREnvelopeEditorCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	//build memory device context to draw to
	CDC			DrawDC;
	CDC*		pDrawDC=&DrawDC;
	CBitmap		MemoryBitmap;
	CBitmap*	pMemoryBitmap=&MemoryBitmap;
	CBitmap*	pOldBitmap;

	pDrawDC->CreateCompatibleDC(pdc);
	pMemoryBitmap->CreateCompatibleBitmap(pdc,rcBounds.right,rcBounds.bottom);
	pOldBitmap=pDrawDC->SelectObject(pMemoryBitmap);
	//refresh m_RCCtrlArea with valid one
	m_RCCtrlArea=rcBounds;
	m_RCCtrlArea.bottom-=CONTROL_BAR_HEIGHT;
	//clear background
	CBrush	brBackground(TranslateColor(AmbientBackColor()));
	pDrawDC->FillRect(m_RCCtrlArea, &brBackground);
	//draw selected area if present
	if(m_bHasSelection) {
		CBrush		brSelection;
		COLORREF	selection_color=TranslateColor(AmbientBackColor());
		BYTE		r_color,g_color,b_color;
		r_color=GetRValue(selection_color);
		g_color=GetGValue(selection_color);
		b_color=GetBValue(selection_color);
		int sum3=((int)r_color+(int)g_color+(int)b_color)/3;
		if(sum3>30) {
			if(r_color>30) r_color-=30;
			else r_color=0;
			if(g_color>30) g_color-=30;
			else g_color=0;
			if(b_color>30) b_color-=30;
			else b_color=0;
		}
		else {
			if(r_color<225) r_color+=30;
			else r_color=255;
			if(g_color<225) g_color+=30;
			else g_color=255;
			if(b_color<225) b_color+=30;
			else b_color=255;
		}
		selection_color=RGB(r_color,g_color,b_color);
		brSelection.CreateSolidBrush(selection_color);
		CRect selection_rect;
		selection_rect.top=0;
		selection_rect.bottom=m_RCCtrlArea.bottom;
		selection_rect.left=translateEnvelopeXToScreenX(m_lFirstSelectedPosition);
		selection_rect.right=translateEnvelopeXToScreenX(m_lLastSelectedPosition);
		pDrawDC->FillRect(&selection_rect,&brSelection);
	}
	//draw X and Y axes
	CPen	axis_pen;
	axis_pen.CreatePen(PS_SOLID,2,RGB(0,0,0));
	CPen*	old_pen;
	old_pen=pDrawDC->SelectObject(&axis_pen);
	//X
	pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(0.0f));
	pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(0.0f));
	//Y
	pDrawDC->MoveTo(translateEnvelopeXToScreenX(0),0);
	pDrawDC->LineTo(translateEnvelopeXToScreenX(0),m_RCCtrlArea.bottom);
	//draw grid
	CPen	grid_pen;
	grid_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
	pDrawDC->SelectObject(&grid_pen);
	//draw control border
	pDrawDC->MoveTo(0,0);
	pDrawDC->LineTo(m_RCCtrlArea.right-1,0);
	pDrawDC->LineTo(m_RCCtrlArea.right-1,m_RCCtrlArea.bottom-1);
	pDrawDC->LineTo(0,m_RCCtrlArea.bottom-1);
	pDrawDC->LineTo(0,0);

	//here grid drawing starts
	long	x_step=calcEnvelopeXStep();
	float	y_step=calcEnvelopeYStep();
	long	x_pos;
	float	y_pos;
	//y
	x_pos=(m_lFirstKeyPosition/x_step+1)*x_step;
	while(x_pos<m_lLastKeyPosition) {
		pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),0);
		pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),m_RCCtrlArea.bottom);
		x_pos+=x_step;
	}
	//x
	y_pos=((float)floor(m_fLowValue/y_step)+1.0f)*y_step;
	while(y_pos<m_fHighValue) {
		pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(y_pos));
		pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(y_pos));
		y_pos+=y_step;
	}

	//draw curve
	CPen	cpEnvelope;
	cpEnvelope.CreatePen(PS_SOLID,2,m_CurveColor);
	pDrawDC->SelectObject(&cpEnvelope);
	x_pos=0;	//beware that now it is screen, not envelope coordinate
	float fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos));
	pDrawDC->MoveTo(x_pos,translateEnvelopeYToScreenY(fEvalRes));
	while(x_pos<m_RCCtrlArea.right) {
		fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos));
		pDrawDC->LineTo(x_pos,translateEnvelopeYToScreenY(fEvalRes));
		x_pos++;
	}
	//draw keys
	if(!(m_bDirtyPositions ||
		m_bDirtyValues)) {
		long i;
		long lNumKeys=m_pEnvelope->getNumKeys();
		for(i=0;i<lNumKeys;i++) {
			drawKey(i,pDrawDC);
		}
	}

	//draw bottom bar
	CBrush		white_brush;
	white_brush.CreateSolidBrush(RGB(255,255,255));
	CRect	rcBottom=rcBounds;
	rcBottom.top=rcBounds.bottom-CONTROL_BAR_HEIGHT;
	pDrawDC->FillRect(rcBottom,&white_brush);
	pDrawDC->SelectObject(&grid_pen);

	//draw bottom bar border
	pDrawDC->MoveTo(0,rcBottom.top);
	pDrawDC->LineTo(rcBottom.right-1,rcBottom.top);
	pDrawDC->LineTo(rcBottom.right-1,rcBottom.bottom-1);
	pDrawDC->LineTo(0,rcBottom.bottom-1);
	pDrawDC->LineTo(0,rcBottom.top);

	//draw vertical lines and frame numbers every 10 x_steps in bottom bar
	CFont	cfFrameFont;
	CString	csFrameString;
	cfFrameFont.CreateFont(8,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEVICE_PRECIS,
		CLIP_DEFAULT_PRECIS,PROOF_QUALITY,FIXED_PITCH,NULL);
	pDrawDC->SelectObject(&cfFrameFont);
	pDrawDC->SetBkMode(TRANSPARENT);
	x_pos=m_lFirstKeyPosition-m_lFirstKeyPosition%(10*x_step)-10*x_step;
	while(x_pos<m_lLastKeyPosition) {
		if((x_pos%(10*x_step))==0) {
			pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),rcBottom.top);
			pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),rcBottom.bottom);
			csFrameString.Format("%d",x_pos);
			pDrawDC->TextOut(translateEnvelopeXToScreenX(x_pos),
				rcBottom.top,csFrameString);
		}
		x_pos+=x_step;
	}
	pDrawDC->SelectObject(old_pen);

	pdc->BitBlt(0,0,rcBounds.right,rcBounds.bottom,pDrawDC,0,0,SRCCOPY);
	
	pDrawDC->SelectObject(pOldBitmap);
	pDrawDC->DeleteDC();
}