⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcanvas.cpp

📁 在linux下多媒体开发实例linux下多媒体开发
💻 CPP
字号:
// tcanvas.cpp// code for implementing drawing canvas#include <iostream.h>#include <v/vdebug.h>#include <v/vwindow.h>#include "tcanvas.h"#include "tchord.h"#include "tutils.h"// names of notes on each string and fretchar *noteNames[numStrings][numFrets] = {  { "E",  "F",  "F#", "G",  "G#", "A",  "A#", "B" },  { "A" , "A#", "B",  "C",  "C#", "D",  "D#", "E" },  { "D" , "D#", "E",  "F",  "F#", "G",  "G#", "A" },  { "G" , "G#", "A",  "A#", "B",  "C",  "C#", "D" },  { "B" , "C",  "C#", "D",  "D#", "E",  "F",  "F#"},  { "E",  "F",  "F#", "G",  "G#", "A",  "A#", "B" }};tCanvasPane::tCanvasPane(){  strings[0] = strings[1] = strings[2] =    strings[3] = strings[4] = strings[5] = 0;  drawNotes = 1;}tCanvasPane::~tCanvasPane(){  strings[0] = strings[1] = strings[2] =    strings[3] = strings[4] = strings[5] = 0;  drawNotes = 1;}void tCanvasPane::Clear(){  vCanvasPane::Clear();       // clear the canvas}void tCanvasPane::Redraw(int px, int py, int pw, int ph){  UserDebug(WindowEvents, "tCanvasPane:Redraw()\n");  int x0, y0; // upper left corner of diagram  int w, h;   // distance between strings and frets  int d;      // radius of dots    // scale the diagram to fit the canvas  w = h = Min(GetHeight()/(numFrets+3), GetWidth()/(numStrings+2));  x0 = (GetWidth() - (numStrings-1)*w)/2;  y0 = (GetHeight() - (numFrets)*h)/2;  d = w/2;    Clear(); // start with a clean slate    // draw the horizontal lines (frets)  for (int i = 0 ; i <= numFrets ; i++) {    DrawLine(x0, y0+i*h, x0+(numStrings-1)*w, y0+i*h);  }    // draw the vertical lines (strings)  for (int i = 0 ; i < numStrings ; i++) {    DrawLine(x0+i*w, y0, x0+i*w, y0+(numFrets)*h);  }    // list the fret numbers  for (int i = 1 ; i <= numFrets ; i++) {    char s[2];    sprintf(s, "%1d", i);    DrawText(x0-w/2, y0+i*h, s);  }  // draw the fingering  for (int i = 0 ; i < numStrings ; i++) {    char s[2] = "X";    s[0] = strings[i];    switch (strings[i]) {    case 'X':    case '0':      {	DrawText(x0+i*w-3, y0-5, s);	break;      }    case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8':      {	int f = strings[i] - '0';	DrawEllipse(x0+i*w-d/2, y0+f*h-d/2-w/2, d, d);	break;      }    default:      {	UserDebug1(BadVals, "tCanvasPane::Redraw() bad string value `%c'", 		   strings[i]);      }    }  }    // note names  if (drawNotes) {    for (int s = 0 ; s < numStrings ; s++) {      int f = strings[s] - '0';      if (f >= 0 && f <= 8) {	DrawText(x0+s*w-3, y0+(numFrets)*h+w-3, noteNames[s][f]);      }    }  }}void tCanvasPane::Resize(int w, int h){  UserDebug(WindowEvents, "tCanvasPane:Resize()\n");  Redraw(0, 0, 0, 0);  vCanvasPane::Resize(w,h);}void tCanvasPane::DrawChord(strings_t strings, int drawNotes){  UserDebug(WindowEvents, "tCanvasPane:DrawChord()\n");  for (int i = 0 ; i < numStrings ; i++) {    tCanvasPane::strings[i] = strings[i];  }  tCanvasPane::drawNotes = drawNotes;  Redraw(0, 0, 0, 0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -