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: Rotating a text  (Read 7148 times)

obones

  • Newbie
  • *
  • Posts: 9
    • View Profile
Rotating a text
« on: September 06, 2021, 04:44:06 PM »

I'm trying to write text at an angle of 15° and so I tried this set of commands:

Code: [Select]
BEGIN(BITMAPS)
CMD_LOADIDENTITY()
CMD_ROTATEAROUND(0, 0, 2731, 65536)
CMD_SETMATRIX()
CMD_TEXT(100, 100, 29, 0, "Test")
END()

But each letter is rotated individually, not the entire text by itself.

How can I achieve this rotation, so that the text looks like this:

Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 733
    • View Profile
Re: Rotating a text
« Reply #1 on: September 07, 2021, 04:54:45 PM »

Hello,

There are several ways to do it and we will post a small example. The text rotation is normally done on a character by character basis or you can rotate the entire completed string as a single bitmap.

Best regards

BRT Community
Logged

Spyy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Rotating a text
« Reply #2 on: January 14, 2022, 07:08:34 PM »

I'm trying to write text at an angle of 15° and so I tried this set of commands:

Code: [Select]
BEGIN(BITMAPS)
CMD_LOADIDENTITY()
CMD_ROTATEAROUND(0, 0, 2731, 65536)
CMD_SETMATRIX()
CMD_TEXT(100, 100, 29, 0, "Test")
END()

But each letter is rotated individually, not the entire text by itself.

How can I achieve this rotation, so that the text looks like this:



Hi,

years ago i used a solution with CMD_SNAPSHOT2. <at startup I wrote the numbers/text i needed on the screen and then took a snapshot with the command and stored them as a bitmap in the memory. Then used the bitmap later. Not ideal but worked.
A better solution very appreciated :)....

Thank you

Torsten
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 733
    • View Profile
Re: Rotating a text
« Reply #3 on: January 14, 2022, 10:14:55 PM »

Hi Obones, Torsten,

Here is a small example of the Bitmap rotation method which you mentioned.

To make it even more universal, you can rotate each letter as a bitmap and use the character width to position each character. This works well for right-angles but for other angles, the step where you calculate the X and Y position of each character relative to the last becomes more complex, and may involve quite a bit of code and trig functions.

For some cases where a random angle is needed and where the word does not constantly change, using a bitmap works well. You could also avoid calculating the widths etc. and hard-code these but using the widths makes sure that the string looks well formatted.

Code: [Select]
EVE_GPU_FONT_HEADER StdFont30;

uint32_t FontByte;
uint16_t FontIndexCounter;
uint32_t FontTableAddress = 0;
uint32_t X = 100;
uint32_t Y = 100;
uint32_t CurrentCharWidth = 0;
uint32_t CurrentCharHeight = 0;
uint8_t offset = 0;
uint32_t angle = 90;
#define FontNum 30


uint32_t StringWidth = 0;
uint32_t StringHeight = 0;
uint32_t SnapWidth = 0;
uint32_t SnapHeight = 0;
uint32_t x_text = 200;
uint32_t y_text = 200;

uint32_t x_coord = 200;
uint32_t y_coord = 200;

// Get the character widths from the ROM font 30
void eve_display(void)
{
FontTableAddress = ((HAL_MemRead32(EVE_ROMFONT_TABLEADDRESS)) + ((FontNum - 16) * FT_GPU_FONT_TABLE_SIZE));

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

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

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

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

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

// 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_TEXT(x_text,y_text, 30, EVE_OPT_CENTER, "Hello"); // Print Hello
// Add up the widths of the characters
StringWidth = (uint32_t) (StdFont30.FontWidth['H'] + StdFont30.FontWidth['e'] + StdFont30.FontWidth['l'] + StdFont30.FontWidth['l'] + StdFont30.FontWidth['o']);// + (StdFont30->FontWidth['e']);// + (uint32_t)(StdFont30->FontWidth["l"]) + (uint32_t)(StdFont30->FontWidth["l"]) + (uint32_t)(StdFont30->FontWidth["o"]);
StringHeight = StdFont30.FontHeightInPixels; // Get the height from the font table
EVE_DISPLAY(); // Finish the display list
EVE_CMD_SWAP();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();

// Get the size for our snapshot, ensuring we include the full string
SnapWidth = StringWidth * 2;
SnapHeight = StringWidth * 2;

// Take a snapshot of the area around the text
// Store it at address 0 of RAM_G
EVE_LIB_BeginCoProList();
EVE_CMD_SNAPSHOT2(EVE_FORMAT_ARGB4, 0, (x_text - (SnapWidth/2)), (y_text - (SnapHeight/2)),  SnapWidth, SnapHeight);
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();

// In this loop, we can constantly rotate the angle to make the word spin round
while(1)
{

if(angle < 360)
angle ++;
else
angle = 0;

EVE_LIB_BeginCoProList();
EVE_CMD_DLSTART();
EVE_CLEAR_COLOR_RGB(0, 0, 0);
EVE_CLEAR(1,1,1);
EVE_COLOR_RGB(255,255,255);

EVE_BEGIN(EVE_BEGIN_BITMAPS);
EVE_BITMAP_SOURCE(0); // Bitmap source is where we stored the snapshot
EVE_BITMAP_SIZE(EVE_FILTER_BILINEAR, EVE_WRAP_BORDER, EVE_WRAP_BORDER,SnapWidth,SnapHeight);
#if (defined EVE2_ENABLE || defined EVE3_ENABLE || defined EVE4_ENABLE)
  EVE_BITMAP_SIZE_H(SnapWidth >> 9, SnapHeight >> 9);
#endif
EVE_BITMAP_LAYOUT(EVE_FORMAT_ARGB4, SnapWidth *2, SnapHeight);
#if (defined EVE2_ENABLE || defined EVE3_ENABLE || defined EVE4_ENABLE)
    EVE_BITMAP_LAYOUT_H((SnapWidth * 2) >> 10, SnapHeight >> 9);
#endif
// Do the rotation
EVE_CMD_LOADIDENTITY();
EVE_CMD_TRANSLATE(65536*(SnapWidth/2),65536*(SnapHeight/2));
EVE_CMD_ROTATE(angle*(65536/360));
EVE_CMD_TRANSLATE(65536*(-SnapWidth/2),65536*(-SnapHeight/2));
EVE_CMD_SETMATRIX();
// Now place the rotated image of the word
EVE_VERTEX2F(x_coord *16,y_coord *16);

EVE_DISPLAY();
EVE_CMD_SWAP();
EVE_LIB_EndCoProList();
EVE_LIB_AwaitCoProEmpty();

MCU_Delay_20ms(); // Prevent it spinning too fast

}
}

Best Regards, BRT Community
Logged

Rudolph

  • Sr. Member
  • ****
  • Posts: 389
    • View Profile
Re: Rotating a text
« Reply #4 on: January 17, 2022, 06:11:05 PM »

Seeing the example reminds me, what about AN025 style export for EVE Screen Editor?
Logged