Now I see something that doesn’t sound nice to me because maybe there will have to be many lines-number-increasing changes. Or maybe won’t, we’ll see.
I was trying to combine DrawDot(), DrawStaccato(), DrawSharp() and DrawFlat() into one method that is using hashtable:
private bool DrawNote(Note note, int idx)
{
if (_editorWindow.XPos + NoteWidth(note) + EditorWindow.CursorWidth > EditorWindow.MelodyFieldBound)
return false;
if (note.IsSharp())
DrawAdditional("Sharp", (int)_pitchLinesY[note.GetPitch().Symbol] + (int)_octaves[note.GetPitch().OctaveShift], idx);
if (note.IsFlat())
DrawAdditional("Flat", (int)_pitchLinesY[note.GetPitch().Symbol] + (int)_octaves[note.GetPitch().OctaveShift], idx);
if (note.IsStaccato())
DrawAdditional("Staccato", (int)_pitchLinesY[note.GetPitch().Symbol] + (int)_octaves[note.GetPitch().OctaveShift], idx);
Bitmap next;
if (note.IsRest())
next = (Bitmap)_durations[note.GetDuration() + "Rest"];
else
next = (Bitmap)_durations[note.GetDuration()];
var noteImg = new Image("Note" + idx, 255, _editorWindow.XPos, (int)_pitchLinesY[note.GetPitch().Symbol] + (int)_octaves[note.GetPitch().OctaveShift], next.Width, next.Height);
noteImg.Bitmap = next;
noteImg.TapEvent += _editorWindow.ElementImgTapEvent;
var backColor = noteImg.Bitmap.GetPixel(0, 0);
noteImg.Bitmap.MakeTransparent(backColor);
_relatedWindow.AddChild(noteImg);
_editorWindow.XPos += next.Width;
_editorWindow.DisplayedNoteCounter++;
if (note.IsDotted())
DrawAdditional("Dot", (int)_pitchLinesY[note.GetPitch().Symbol] + (int)_octaves[note.GetPitch().OctaveShift], idx);
return true;
}
//...
private readonly Hashtable _additionalResources = new Hashtable
{
{"Dot", DotData},
{"Staccato", StaccatoData},
{"Sharp", SharpData},
{"Flat", FlatData}
};
private static readonly ArrayList DotData = new ArrayList { Resources.GetBitmap(Resources.BitmapResources.dotTh), 2, 16, 2 };
private static readonly ArrayList StaccatoData = new ArrayList { Resources.GetBitmap(Resources.BitmapResources.dotTh), 4, 23, -1 };
private static readonly ArrayList SharpData = new ArrayList { Resources.GetBitmap(Resources.BitmapResources.sharpTh), 0, 9, 0 };
private static readonly ArrayList FlatData = new ArrayList { Resources.GetBitmap(Resources.BitmapResources.flatTh), 0, 5, 0 };
private void DrawAdditional(string name, int noteY, int idx)
{
var next = (Bitmap)((ArrayList)_additionalResources[name])[0];
var dotImg = new Image(name + idx, 255, _editorWindow.XPos + (int)((ArrayList)_additionalResources[name])[1], noteY + (int)((ArrayList)_additionalResources[name])[2], next.Width, next.Height);
dotImg.Bitmap = next;
dotImg.TapEvent += _editorWindow.ElementImgTapEvent;
var backColor = dotImg.Bitmap.GetPixel(0, 0);
dotImg.Bitmap.MakeTransparent(backColor);
_relatedWindow.AddChild(dotImg);
if (name != "Staccato")
_editorWindow.XPos += next.Width + (int)((ArrayList)_additionalResources[name])[3];
}
And I was counting ticks inside DrawNote()
And here are the results:
With hashtable:
Drawing only a note - 27ms
Drawing a dotted note - 27ms
Drawing a note with staccato - 60ms
Drawing a sharp note - 66ms
Drawing a flat note - 69ms
Drawing a dotted sharp note - 109ms
Drawing a flat note with staccato - 115ms
Total: 473ms
Without hashtable:
Drawing only a note - 27ms
Drawing a dotted note - 56ms - this is worse, but everything below is better
Drawing a note with staccato - 53ms
Drawing a sharp note - 60ms
Drawing a flat note - 62ms
Drawing a dotted sharp note - 98ms
Drawing a flat note with staccato - 104ms
Total: 460ms
Well, ok… If choosing this particular sequence, total drawing time without hashtables is slightly shorter than with hashtable.
I thought that it the total difference may be bigger, but ok. Now I’m just trying to figure out whether combining four or more functions into one with hashtable is a good manner?
Regards.
Tomasz
Edit:
I think I should try to make DeleteQuestionBox, CancelQuestionBox and NumericalInputWindow to be deleted, and then rectangle with proper content will pop up when needed.