/// <summary> /// This method takes a string with each char (byte) representing the locations of active /// on a CyCustomCharacterArray. /// </summary> /// <param name="customCharacter"> The instance of a character to be updated from CyDesigner data.</param> /// <param name="cyParameterString"> The string representing byte array from CyDesigner.</param> public void CyParameterToCustomCharacter(CyCustomCharacter customCharacter, string cyParameterString) { char[] chars = new char[customCharacter.Rows]; int index = 0; // Remove last comma and seperate into indivudual strings. string[] hexCharacterArray = cyParameterString.TrimEnd(',').Split(','); for (int i = 0; i < hexCharacterArray.Length; i++) { chars[index++] = (char)byte.Parse(hexCharacterArray[i], System.Globalization.NumberStyles.HexNumber); } CharLCDmp_v1_1.CyBox[,] boxes = customCharacter.GetBoxArray(); for (int row = 0; row < customCharacter.Rows; row++) { for (int column = 0; column < customCharacter.Columns; column++) { if ((((byte)chars[row]) & getExponent(customCharacter.Columns - 1 - column)) != 0) { boxes[row, column].IsActive = true; } } } }
/// <summary> /// This method takes a user defined custom character and converts the locations of active /// pixels to an array of bytes, cast into a string to be stored on the LCD component object in CyDesigner. /// </summary> /// <param name="customCharacter"> The string representing byte array from CyDesigner.</param> public string CharacterToCYString(CyCustomCharacter customCharacter) { // Comma Seperated String of Hex Values string cyCharacterString = ""; CharLCDmp_v1_1.CyBox[,] pixelArray = customCharacter.GetBoxArray(); // Indivudual row value to be calculated byte rowValue; for (int row = 0; row < customCharacter.Rows; row++) { rowValue = 0; for (int column = 0; column < customCharacter.Columns; column++) { if (pixelArray[row, column].IsActive) { // If active find out which pixel it is. The 0th is the furthest right // and has a value of 1. 'customCharacter.Columns - 1' is the furthest left // and has a value of 2^(customCharacter.Columns -1). Values in between are // Exponential powers of 2 based on position. rowValue += (byte)getExponent(customCharacter.Columns - 1 - column); } } cyCharacterString += rowValue.ToString("X") + ","; } // Convert Char arry to string and return it. return(cyCharacterString); }
// Calls CyStringToCharacter Foreach Character private void UnpackageCyStrings() { int stringIndex = 0; string value; for (int index = 0; index < 8; index++) { value = m_component.GetCommittedParam(CHARACTER_PARAM_NAME + index).Value.Trim('"'); m_cyCharacterStrings.Add(new KeyValuePair <string, string>(CHARACTER_PARAM_NAME + index, value)); } //if (m_userDefinedCharacters.Count != m_cyCharacterStrings.Count) // throw new Exception( // "Number of custom characters in CyDesigner does not match number supported by the the LCD Wizard"); for (int i = 0; i < m_userDefinedCharacters.Count; i++) { CyCustomCharacter character = (CyCustomCharacter)m_userDefinedCharacters[i]; KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)m_cyCharacterStrings[stringIndex++]; string cyCharacterString = kvp.Value; if (cyCharacterString != null) { CYStringToCharacter(character, cyCharacterString); } } }
private void UpdateHighlighted(CyCustomCharacter selectedCharacter) { m_highlighted.Match(characterEditor); m_highlighted.Selected = false; m_highlighted.Invalidate(); m_highlighted = selectedCharacter; m_highlighted.Selected = true; m_highlighted.Invalidate(); currentEditableCharacter.Text = m_highlighted.DisplayName; this.characterEditor.Match(selectedCharacter); this.characterEditor.Invalidate(); }
private void custArray_MouseDown(object sender, MouseEventArgs e) { CharLCDmp_v1_1.CyCustomCharacter current = (CharLCDmp_v1_1.CyCustomCharacter)sender; CharLCDmp_v1_1.CyBox clickedBox = current.GetBoxByLocation(e.X, e.Y); if (clickedBox != null) { clickedBox.IsActive = !clickedBox.IsActive; m_activate = clickedBox.IsActive; current.Invalidate(); } this.m_highlighted.Invalidate(); }
// Convert userDefined Characters to CyStrings private void ConvertUserDefinedCharactersToCY() { int stringIndex = 0; for (int i = 0; i < m_userDefinedCharacters.Count; i++) { CyCustomCharacter character = (CyCustomCharacter)m_userDefinedCharacters[i]; KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)m_cyCharacterStrings[stringIndex++]; string cyStringName = kvp.Key; string cyStringValue = "\"" + CharacterToCYString(character) + "\""; m_component.SetParamExpr(cyStringName, cyStringValue); } }
private void CustomCharactersOn() { customCharacterGroupBox.Enabled = true; m_highlighted.Selected = true; for (int i = 0; i < this.panel1.Controls.Count; i++) { CharLCDmp_v1_1.CyCustomCharacter character = (CharLCDmp_v1_1.CyCustomCharacter) this.panel1.Controls[i]; character.BorderBrush = new SolidBrush(Color.LightGray); character.ActiveBrush = new SolidBrush(Color.Black); character.InactiveBrush = new SolidBrush(Color.White); character.Invalidate(); } }
private void custArray_MouseMove(object sender, MouseEventArgs e) { if ((e.Button == MouseButtons.Left) || (e.Button == MouseButtons.Right)) { CharLCDmp_v1_1.CyCustomCharacter current = (CharLCDmp_v1_1.CyCustomCharacter)sender; CharLCDmp_v1_1.CyBox currentBox = current.GetBoxByLocation(e.X, e.Y); if (currentBox != null) { currentBox.IsActive = m_activate; current.Invalidate(); } } this.m_highlighted.Invalidate(); }
// Load the User Defined Characters into CharLCDCustomizer ArrayList userDefinedCharacters. ArrayList LoadUserDefinedCharacters(Dictionary <string, string> parameters) { int index = 0; string temp = ""; ArrayList characters = new ArrayList(); while (parameters.TryGetValue(UD_PARAM + index.ToString(), out temp)) { CyCustomCharacter character = new CyCustomCharacter(); temp = temp.Trim('"').TrimEnd(','); CyParameterToCustomCharacter(character, temp); characters.Add(character); index++; } return(characters); }
private void CustomCharactersOff() { m_highlighted.Selected = false; for (int i = 0; i < this.panel1.Controls.Count; i++) { CharLCDmp_v1_1.CyCustomCharacter character = (CharLCDmp_v1_1.CyCustomCharacter) this.panel1.Controls[i]; if (character.Visible == true) { character.ActiveBrush = new SolidBrush(Color.LightGray); character.InactiveBrush = new SolidBrush(Color.WhiteSmoke); character.BorderBrush = new SolidBrush(Color.LightGray); character.Invalidate(); } } customCharacterGroupBox.Enabled = false; }
// Given a CustomCharacter, convert it into the lines of code to build an LCD custom char Array. string CharacterToCCode(CyCustomCharacter customCharacter) { // "characterString" represents the character after conversion to C Code String characterString = ""; CharLCDmp_v1_1.CyBox[,] pixelArray = customCharacter.GetBoxArray(); // Indivudual row value to be calculated byte rowValue; for (int row = 0; row < customCharacter.Rows; row++) { rowValue = 0; for (int column = 0; column < customCharacter.Columns; column++) { if (pixelArray[row, column].IsActive) { // If active find out which pixel it is. The 0th is the furthest right // and has a value of 1. 'customCharacter.Columns - 1' is the furthest left // and has a value of 2^(customCharacter.Columns -1). Values in between are // Exponential powers of 2 based on position. rowValue += (byte)getExponent(customCharacter.Columns - 1 - column); } } // Convert to 2 digit hex. Build Code for this row of the character. string temp = rowValue.ToString("X"); if (temp.Length != 2) { characterString += String.Format(" 0x0{0}u", rowValue.ToString("X")); } else { characterString += String.Format(" 0x{0}u", rowValue.ToString("X")); } // No Comma after the last hex value if (row != customCharacter.Rows - 1) { characterString += ","; } } return(characterString); }
// Given an ArrayList of Characters, convert array list into a C Data File. private void ConvertCharacters(ArrayList customCharacters, Dictionary <string, string> dict) { int stringIndex = 0; string key = ""; string value = ""; for (int i = 0; i < customCharacters.Count; i++) { CyCustomCharacter character = (CyCustomCharacter)customCharacters[i]; // Define Value value = CharacterToCCode(character); // Define Key Name key = CUST_CHAR_MACRONAME + stringIndex.ToString(); dict.Add(key, value); stringIndex++; } }
// Create bar graphs activates the appropriate pixels on two bargraph // Sets, horizontal and vertical: May need adjustments in future. private void CreateBarGraphs() { #region Horizontal Bargraph int largestColumn = 0; // Loop returns items in the order they were added to the ArrayList. for (int i = 0; i < m_hbgCharacters.Count; i++) { CyCustomCharacter character = (CyCustomCharacter)m_hbgCharacters[i]; for (int index = 0; index < largestColumn; index++) { character.SetColumn(index); } largestColumn++; if (largestColumn > character.Columns) { break; } } #endregion #region Vertical Bargraph // Does not leave an empty character in the Custom Fonts int lastRow = 7; for (int i = 0; i < m_vbgCharacters.Count; i++) { CyCustomCharacter character = (CyCustomCharacter)m_vbgCharacters[i]; for (int index = 7; index >= lastRow; index--) { character.SetRow(index); } lastRow--; } #endregion }
private void custArrayHighlight_Click(object sender, MouseEventArgs e) { CharLCDmp_v1_1.CyCustomCharacter selectedCharacter = (CharLCDmp_v1_1.CyCustomCharacter)sender; UpdateHighlighted(selectedCharacter); }