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: Rotate text  (Read 63 times)

GuyVerachtert

  • Newbie
  • *
  • Posts: 2
    • View Profile
Rotate text
« on: May 07, 2019, 03:58:40 PM »

hi !

Is there a way to rotate text ? (not display at an angle like in the tutorial)
I found that this can be done for bitmaps, but i can't find it for text...

Thank you,

Guy
Logged

BRT Community

  • Administrator
  • Newbie
  • *****
  • Posts: 36
    • View Profile
Re: Rotate text
« Reply #1 on: May 08, 2019, 11:07:12 AM »

Hello,

The following is an Arduino example which creates a rotated button and then places some rotated text on top of this:
Code: [Select]
void Widgets()
{
    uint8_t imagewidth = 16;                                // In this case it is width of the font character. Used when rotating
    uint8_t imageheight = 25;                               // In this case it is height of the font character. Used when rotating
    uint8_t CharSpacing = 18;                               // Spacing desired between characters when writing string
    int16_t imagexoffset;
    int16_t imageyoffset;
   
    int16_t ButtonWidth;
    int16_t ButtonHeight;
    int16_t ButtonXred;
   int16_t ButtonYred;
    int16_t TextXred;
    int16_t TextYred;
    bool Button1Pressed = false;

    const char Display_string_red[4] = "Red";                // Text for button
    uint8_t stringlenred = sizeof(Display_string_red)-1;     // Calculate the string length of the text to be displayed 

    uint8_t j = 0;
   
    // Calculate positions ... note that X, Y, Width and Height are all relating to landscape orinetation as this is the normal FT800 orientation
    // All references could be reversed if preferred
       
    ButtonHeight = 100;                                                                        // Height of button (width in portrait)
    ButtonWidth = 40;                                                                          // Width of button (height in portrait)

    ButtonXred = ((FT_DISPLAYWIDTH / 2) - (ButtonWidth / 2));                                  // Middle of screen taking account of button width
    ButtonYred = ((FT_DISPLAYHEIGHT / 2) - (ButtonHeight / 2));                                // Middle of screen taking account of button height
   
    TextXred = ButtonXred + (ButtonWidth / 4);                                                 // Top of text characters is 1/4th way down button - appears centred
    TextYred = ButtonYred + (ButtonHeight - imageheight);                                      // Text starts at left hand side of button - left justified
                                                                                               // note that origin of button is still top-left when screen in landscape orientation
                                                                         
    while(1)
    {
        FTImpl.DLStart(); 
       
        // set screen colour depending on whether button pressed
        if(Button1Pressed == true)
        {
            FTImpl.ClearColorRGB(255,0,0);                                                     // Set the background color to red if button pushed
        }
        else
        {
            FTImpl.ClearColorRGB(64,64,64);                                                    // Set the background color to grey
        } 
             
        FTImpl.Clear(1,1,1);                                                                   // Clear the background to the colour above
               
        FTImpl.ColorRGB(255, 255, 255);                                                        // Current drawing colour is white

        // draw buttons and tag them

        FTImpl.TagMask(1);                                                                     // un-mask tag so that we can tag objects

        FTImpl.Tag(1);                                                                         // any following objects will be tagged '1'
       
        FTImpl.Cmd_Button(ButtonXred,ButtonYred,ButtonWidth,ButtonHeight,27,0,"");             // draw button with no text

        FTImpl.TagMask(0);                                                                     // mask tag in case we were going to draw any other objects below

        // add text rotated on top of buttons
       
        FTImpl.Begin(FT_BITMAPS);                                                              // start drawing bitmaps

        imagexoffset = TextXred;
        imageyoffset = TextYred;

       for (j = 0; j<stringlenred; j++)
        {
           FTImpl.Cmd_LoadIdentity();                                                         // Load identity matrix
            FTImpl.Cmd_Translate( 65536*imagewidth/2,65536*imageheight/2);                     // Move bitmap image (letter of string) by half it's size so that it can rotate without clipping corner
           FTImpl.Cmd_Rotate( -90*65536/360);                                                 // Rotate by 90 degrees anticlock wise
            FTImpl.Cmd_Translate( -65536*imagewidth/2,-65536*imageheight/2);                   // move it back to original position after rotation
           FTImpl.Cmd_SetMatrix( );                                                           // Assign the current matrix
            FTImpl.Vertex2ii(imagexoffset,imageyoffset, (24), Display_string_red[j]);          // Draw the actual character (bitmap)
            imageyoffset -= CharSpacing;

       }

        FTImpl.DLEnd();                                                                        // end the display list
        FTImpl.Finish();                                                                       // render the display list and wait for the completion of the DL

        // now check the tag register to see if a tagged area is being touched.
        // reg_tag will read 0 if no touch or if an area is touched which is not tagged.
        // otherwise it will contain the value of the tag number of the area being touched

         Button1Pressed = false;

         Read_tag = FTImpl.Read(REG_TOUCH_TAG);
               
         if(Read_tag == 1)
         {
             Button1Pressed = true;
         }
    }
             
       
       
}

This example uses proportional font spacing, defined as CharSpacing

Code: [Select]
            FTImpl.Vertex2ii(imagexoffset,imageyoffset, (24), Display_string_red[j]);          // Draw the actual character (bitmap)
            imageyoffset -= CharSpacing;

It would be possible to look up the individual character widths and space each letter accordingly.
Please email support.emea@brtchip.com if you wish to receive a draft application note which covers how to do this.

Best Regards,
BRT Community
Logged

GuyVerachtert

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Rotate text
« Reply #2 on: May 09, 2019, 09:59:24 AM »

Thank you for your reply !

Do you have a full arduino example ?
I am using a Nero.

Kind regards,

guy
Logged

BRT Community

  • Administrator
  • Newbie
  • *****
  • Posts: 36
    • View Profile
Re: Rotate text
« Reply #3 on: May 09, 2019, 03:21:28 PM »

Hello,

You can find examples at the following, these include arduino samples within the project structure:
https://brtchip.com/SoftwareExamples-eve/


Best Regards,
BRT Community
Logged