BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: Line vs text or number  (Read 5900 times)

Spyy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Line vs text or number
« on: January 20, 2022, 12:45:36 AM »

Hi,

just to be sure to be on the right track...

I can "create/move" lines/rects/points/etc. with a precision of 1/16 pixel with VERTEX2F. But this is not possible with CMD_TEXT, CMD_NUMBER, VERTEXII and a font. There is the precision of 1 pixel...?
Or is there a way to do text/numbers with the same precision, or i am completely wrong here?

Thank you for your help

Torsten
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 732
    • View Profile
Re: Line vs text or number
« Reply #1 on: January 21, 2022, 12:06:26 PM »

Hi,

Most of these items are positioned by the pixel rather than by 1/16th. When used in code examples, you will see that Vertex2F has the value multiplied by 16 e.g. VERTEX2F(20*16, 20*16) to place something at coordinate 20,20. Note that you can actually also display numbers and letters using VERTEX2F as they are made up of a series of images (one per character).

Also note that using the text command does all the character spacing etc for you. If you use Vertex2F this only places 1 character per vertex and so to make a string of characters you will need to call a Vertex2f per character.

It is possible to just add a value to the x coordinate each time but if you want the text to look proportional (and so spacing between each char related to the width of the char) then you can use the metric block data/font properties which is in the EVE chip. For numbers you might want a fixed position for each number so that the whole number does not move around and change in length (e.g. a 1 is narrower than an 8 ) but for text, having a constant spacing between characters may not look as good.

Best regards

BRT Community
Logged

Jonathan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Line vs text or number
« Reply #2 on: May 25, 2022, 05:27:58 PM »

Hello,

is there a way to get the length of a text in pixel?
For example:
I am creating a custom button with text on it and I want the button width to be calculated automatically according to the given text input. Since some letters are bigger than others two words with the same number of letters will have different lengths in pixel.
Example:
Banana
Isabel

Both have 6 letters but different lengths in pixels.

So I am wondering if there is a method to get the size in pixels of the text?

Best
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 732
    • View Profile
Re: Line vs text or number
« Reply #3 on: May 27, 2022, 04:28:39 PM »

Hello,

Please find an initial example below that determines the size of a button based upon the size of characters used. You can use this as a starting point to add, for example, more error checking and optimise it further. We will fine tune it and add an accompanying readme before adding it to our Github examples, but in the meantime please give this one a try.

Best regards, BRT Community

Code: [Select]
/**
 * (C) Copyright,  Bridgetek Pte. Ltd.
 * ============================================================================
 *
 * This source code ("the Software") is provided by Bridgetek Pte Ltd
 * ("Bridgetek") subject to the licence terms set out
 * http://www.ftdichip.com/FTSourceCodeLicenceTerms.htm ("the Licence Terms").
 * You must read the Licence Terms before downloading or using the Software.
 * By installing or using the Software you agree to the Licence Terms. If you
 * do not agree to the Licence Terms then do not download or use the Software.
 *
 * Without prejudice to the Licence Terms, here is a summary of some of the key
 * terms of the Licence Terms (and in the event of any conflict between this
 * summary and the Licence Terms then the text of the Licence Terms will
 * prevail).
 *
 * The Software is provided "as is".
 * There are no warranties (or similar) in relation to the quality of the
 * Software. You use it at your own risk.
 * The Software should not be used in, or for, any medical device, system or
 * appliance. There are exclusions of Bridgetek liability for certain types of loss
 * such as: special loss or damage; incidental loss or damage; indirect or
 * consequential loss or damage; loss of income; loss of business; loss of
 * profits; loss of revenue; loss of contracts; business interruption; loss of
 * the use of money or anticipated savings; loss of information; loss of
 * opportunity; loss of goodwill or reputation; and/or loss of, damage to or
 * corruption of data.
 * There is a monetary cap on Bridgetek's liability.
 * The Software may have subsequently been amended by another user and then
 * distributed by that other user ("Adapted Software").  If so that user may
 * have additional licence terms that apply to those amendments. However, Bridgetek
 * has no liability in relation to those amendments.
 * ============================================================================
 */

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "EVE.h"
#include "../include/HAL.h"
#include "MCU.h"
#include "eve_example.h"


void eve_display(void)
{
#define FontNum 28

EVE_GPU_FONT_HEADER StdFont;
uint32_t FontByte;
uint16_t FontIndexCounter;
uint32_t FontTableAddress = 0;
uint32_t StringWidth = 0;
char ButtonText[100];
char letter;
int ButtonTextlength = 0;
uint8_t CharWidth = 0;

// -----------------------------------------------------------------------------------------------------------------------
// Get the character widths from the ROM font
// -----------------------------------------------------------------------------------------------------------------------

FontTableAddress = ((HAL_MemRead32(EVE_ROMFONT_TABLEADDRESS)) + ((FontNum - 16) * FT_GPU_FONT_TABLE_SIZE));

    FontIndexCounter = 0;
    while(FontIndexCounter < 128)
    {
        FontByte = HAL_MemRead8(FontTableAddress + FontIndexCounter);
        StdFont.FontWidth[FontIndexCounter] = FontByte;
        FontIndexCounter ++;
    }
    FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
    StdFont.FontBitmapFormat = FontByte;
    FontIndexCounter = FontIndexCounter + 4;

    FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
    StdFont.FontLineStride = FontByte;
FontIndexCounter = FontIndexCounter + 4;

FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontWidthInPixels = FontByte;
FontIndexCounter = FontIndexCounter + 4;

FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontHeightInPixels = FontByte;
FontIndexCounter = FontIndexCounter + 4;

FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.PointerToFontGraphicsData = FontByte;

// -----------------------------------------------------------------------------------------------------------------------
// Set the string for the button and determine the length as a sum of the widths of individual characters
// -----------------------------------------------------------------------------------------------------------------------

sprintf(ButtonText, "Hello 12345 abcde"); // Text to go in the button
ButtonTextlength = strlen(ButtonText); // get the length of the string

// For each letter, get the character width and add them up
uint8_t i = 0;
for (i = 0; i < ButtonTextlength; i++)
{
letter = ButtonText[i];
CharWidth = StdFont.FontWidth[letter];
StringWidth += (uint32_t)(CharWidth);
}

// -----------------------------------------------------------------------------------------------------------------------
// Draw the button
// -----------------------------------------------------------------------------------------------------------------------

// Write the text Hello and also calculate what width it is based on the characters
EVE_LIB_BeginCoProList(); // Begin co-processor commands
EVE_CMD_DLSTART(); // New display list
EVE_CLEAR_COLOR_RGB(0, 0, 0); // Clear screen to black
EVE_CLEAR(1,1,1); // Clear
EVE_COLOR_RGB(255,255,255); // White color for text
EVE_CMD_BUTTON(100, 100, (StringWidth + 20), 40, FontNum, 0, ButtonText); // Button
EVE_CMD_NUMBER(100, 200, FontNum, 0, StringWidth); // Print the length of the text
EVE_DISPLAY(); // Finish the display list
EVE_CMD_SWAP(); // Swap to make the list active
EVE_LIB_EndCoProList(); // Finish the list of commands
EVE_LIB_AwaitCoProEmpty(); // And wait until complete

while(1)
{
}

}


void eve_example(void)
{
EVE_Init();

eve_display();
}
Logged