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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - BRT Community

Pages: [1] 2 3 ... 44
1
Discussion - EVE / Re: Drawing arcs and circles
« on: March 29, 2023, 05:25:31 PM »
Hi,

Here is a small example of one way to use edge strips to draw an arc.

We can post an explanation too of how it works when ready. The only dependency is that you need cos and sin functions.
When drawing an arc using stencilling, the edge strips provide a good way to shade in an angle. However, each one (top, bottom, left, right) generally only work well for associated 90 degree areas and so we need to use more than one to make this arc.

This is just a basic one but we have used this technique for various arc gauge styles. You can add a point to make the leading and training edges rounded etc or a large point on the leading edge depending on the style which you want. You can also add more error checking etc. to handle out of range values.

It takes in various parameters including the max angle, min angle and the active value which defines how much of the arc is filled in.

p.s. one way to see what is happening is to comment out the line which turns off the color updates EVE_COLOR_MASK(0, 0, 0, 0);   and set a COLOR_RGB for each section.
Here is a small illustration attached showing how the centre circles, the wedge at the bottom and the four quadrant edge strips form a stencil which can then be colored in to make the active part of the arc.

Hope it helps,
BRT Community


Code: [Select]
void Custom_Widget_Arc_Gauge(uint16_t arc_centerx, uint16_t arc_centery, uint16_t arc_radius, uint16_t arc_thickness, uint32_t Arc_Active_Color, uint32_t Arc_Inactive_Color, uint16_t arc_min_limit, uint16_t arc_max_limit, uint16_t arc_value)
{
double arc_value_rad = 0;
uint16_t arc_activex = 0;
uint16_t arc_activey = 0;

double arc_min_limit_rad = 0;
uint16_t arc_start_x = 0;
uint16_t arc_start_y = 0;

double arc_max_limit_rad = 0;
uint16_t arc_end_x = 0;
uint16_t arc_end_y = 0;

//--------------------------------------------------------------------------------------------------------
// Process the angle data which will be used to make a uniform motion of the arc
//--------------------------------------------------------------------------------------------------------

// Ensure the value is within limits
if(arc_value > arc_max_limit)
arc_value = arc_max_limit;
if(arc_value < arc_min_limit)
arc_value = arc_min_limit;

//---------------------------------------------------------

// Calculate the angle in Radians for the Cos and Sin functions
// radians = ((degrees*pi)/180)

// For the arc which we will fill (the actual value of the arc gauge)
// Note: 0 degress is at the very bottom of the circle
if(arc_value > 180)
arc_value_rad = ((arc_value-180) * 3.14)/180;
else
arc_value_rad = (arc_value * 3.14)/180;

// For the min limit which can be for example at 20 degrees from the bottom
if(arc_min_limit > 180)
arc_min_limit_rad = ((arc_min_limit-180) * 3.14)/180;
else
arc_min_limit_rad = (arc_min_limit * 3.14)/180;

// For the max limit which can be for example at 340 degrees from the bottom
if(arc_max_limit > 180)
arc_max_limit_rad = ((arc_max_limit-180) * 3.14)/180;
else
arc_max_limit_rad = (arc_max_limit * 3.14)/180;

//---------------------------------------------------------

// Calculate the coordinates of the starting point, the gauge arc and the point at the tip of the arc

// for the arc gauge itself
arc_activex = (sin(arc_value_rad) * arc_radius);
arc_activey = (cos(arc_value_rad) * arc_radius);

// for the starting angle (the minimum value of the arc as it is normally not desired to be a full 360 deg circle)
arc_start_x = (sin(arc_min_limit_rad) * arc_radius);  
arc_start_y = (cos(arc_min_limit_rad) * arc_radius);         

// for the finishing angle (the maximum value of the arc as it is normally not desired to be a full 360 deg circle)
arc_end_x = (sin(arc_max_limit_rad) * arc_radius);     
arc_end_y = (cos(arc_max_limit_rad) * arc_radius);         

//--------------------------------------------------------------------------------------------------------
// Write to the stencil buffer and disable writing to the screen to make an invisible arc
//--------------------------------------------------------------------------------------------------------

// Set the stencil to increment and diasble writes to the screen
EVE_STENCIL_OP(EVE_STENCIL_INCR, EVE_STENCIL_INCR);
EVE_COLOR_MASK(0, 0, 0, 0);

// Draw concentric circles to form the stencil so that the arc has a unique stencil value and we can shade it later
EVE_BEGIN(EVE_BEGIN_POINTS);

// Outer circle makes the outer edge of the arc
EVE_POINT_SIZE(arc_radius*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);

// Inner circle makes the inner edge of the arc
EVE_POINT_SIZE((arc_radius - arc_thickness)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_END();

//--------------------------------------------------------------------------------------------------------
// Draw the edge strips which will fill in the arc
//--------------------------------------------------------------------------------------------------------

// These are drawn per quadrant as each edge strip will only work well on an angle up to 90 deg

// 0 - 89 Deg
if((arc_value > 0) && (arc_value < 90))
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_B);
EVE_VERTEX2F(((arc_centerx - arc_start_x)*16), (arc_centery+arc_start_y)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx - arc_activex)*16), (arc_centery + arc_activey)*16);
}
else
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_B);
EVE_VERTEX2F(((arc_centerx - arc_start_x)*16), (arc_centery+arc_start_y)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx - arc_radius)*16), (arc_centery)*16);
}

// 90 - 179 deg
if((arc_value >= 90)&& (arc_value < 180))
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_L);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx - arc_activex)*16), (arc_centery - arc_activey)*16);
}
else if (arc_value > 90)
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_L);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery - arc_radius)*16);
}

// 180 - 269 deg
if((arc_value >= 180)&& (arc_value < 270))
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_A);
EVE_VERTEX2F(((arc_centerx-1)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx + arc_activex)*16), (arc_centery - arc_activey)*16);
}
else if (arc_value > 180)
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_A);
EVE_VERTEX2F(((arc_centerx-1)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx + arc_radius )*16), (arc_centery)*16);
}

// 270 - 359 deg
if((arc_value > 270)&& (arc_value < 360))
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_R);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx + arc_activex)*16), (arc_centery + arc_activey)*16);
}
else if (arc_value > 270)
{
// Edge strip to draw the arc
EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_R);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery + arc_radius)*16);
}

// and finally draw a wedge shape at the bottom to ensure the inactive part of the arc is not coloured in

EVE_BEGIN(EVE_BEGIN_EDGE_STRIP_B);
EVE_VERTEX2F(((arc_centerx - arc_start_x)*16), (arc_centery + arc_start_y)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
EVE_VERTEX2F(((arc_centerx + arc_end_x)*16), (arc_centery + arc_end_y)*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);

EVE_END();

//--------------------------------------------------------------------------------------------------------
// Draw a circle which will fill the arc
//--------------------------------------------------------------------------------------------------------

// Stop incrementing the stencil
EVE_STENCIL_OP(EVE_STENCIL_KEEP, EVE_STENCIL_KEEP);
// re-enable writes to the screen
EVE_COLOR_MASK(1, 1, 1, 1);

// For the Active arc area, only draw in areas with stencil == 3
EVE_STENCIL_FUNC(EVE_TEST_EQUAL, 3, 255);
EVE_BEGIN(EVE_BEGIN_POINTS);
EVE_COLOR_RGB( ((uint8_t)(Arc_Active_Color>>16)), ((uint8_t)(Arc_Active_Color>>8)),  ((uint8_t)(Arc_Active_Color)));
EVE_POINT_SIZE(arc_radius*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
////////EVE_END();

// For the Inactive area of the arc, only draw in areas with stencil == 2
EVE_STENCIL_FUNC(EVE_TEST_EQUAL, 2, 255);
EVE_BEGIN(EVE_BEGIN_POINTS);
EVE_COLOR_RGB( ((uint8_t)(Arc_Inactive_Color>>16)), ((uint8_t)(Arc_Inactive_Color>>8)),  ((uint8_t)(Arc_Inactive_Color)));
EVE_POINT_SIZE(arc_radius*16);
EVE_VERTEX2F(((arc_centerx)*16), (arc_centery)*16);
////////EVE_END();

EVE_END();

//--------------------------------------------------------------------------------------------------------
// Clean up to avoid affecting other items later in the display list
//--------------------------------------------------------------------------------------------------------

EVE_STENCIL_FUNC(EVE_TEST_ALWAYS, 1, 255); // Revert to always drawing for the subsequent items

EVE_CLEAR(0,1,0); // Clear the stencil buffer to ensure it does not affect other items on the screen
}

//###############################################################################################################################################################
//###############################################################################################################################################################

void eve_display(void)
{

uint16_t arc_value = 40; // actual value
uint8_t direction = 0; // 0 means count up

while(1)
{
EVE_LIB_BeginCoProList();                                               // Begin new screen
EVE_CMD_DLSTART();                                                      // Tell co-processor to create new Display List

EVE_CLEAR_COLOR_RGB(0x00, 0x55, 0xFF);                                  // Specify color to clear screen to
EVE_CLEAR(1,1,1);                                                       // Clear color, stencil, and tag buffer

EVE_COLOR_RGB(255, 255, 255);
EVE_CMD_NUMBER(200, 200, 30, EVE_OPT_CENTERX, arc_value); // Print numerical arc value

EVE_COLOR_RGB(255, 255, 255);

//                      position Diam  Arc    Arc color  Arc color ----values------
//                                            active      backgnd   limit    arc
//                       X    Y  Size width    RRGGBB      RRGGBB  min max  value
Custom_Widget_Arc_Gauge(200, 200, 180, 30,   0xFF6000,  0x800080, 40, 320, arc_value);

EVE_DISPLAY();                                                          // Tell EVE that this is end of list
EVE_CMD_SWAP();                                                         // Swap buffers in EVE to make this list active

EVE_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
EVE_LIB_AwaitCoProEmpty();                                              // Wait until co-processor has consumed all commands

if(direction == 0)
{
arc_value ++;
if(arc_value == 320)
direction = 1; // count down next time
}
else
{
arc_value --;
if(arc_value == 40)
direction = 0; // count up next time
}
}
}

2
Discussion - EVE / Re: Drawing arcs and circles
« on: March 23, 2023, 01:02:52 PM »
Hi,

Do you have SIN and COS functions in your MCU code framework?
It can be done using just the EVE commands (we can send an example) but ideally it works best if you have these trig functions available (either full or via lookup table).

Best Regards,
BRT Community

3
Discussion - EVE / Re: Drawing arcs and circles
« on: March 20, 2023, 01:13:07 PM »
Hi,

As you said Rudolph, two dots is a good way to make an un-filled circle.

Blending/stencilling can be used to create an arc by drawing an edge strip to overlap the active or non-active area of the circle if you want to have a certain quadrant shown and then only displaying the part of the circle which is within this arc. This is similar to the technique we often use to draw an arc gauge. We can create and post a small example here once it is ready.

Best Regards, BRT Community

 

4
Discussion - EVE / Re: Disable AUDIO_L output signal
« on: March 10, 2023, 10:07:39 AM »
Hi,

Could you advise which EVE device you have?

Best Regards, BRT Community

5
Discussion - EVE / Re: Widgets
« on: March 09, 2023, 05:01:16 PM »
Hello,

Quote from: BRT Community
Have you chosen an MCU to use as a SPI master interface yet?

Thank you but I already developed my own ESP32 library and a decompiler to iterate in CI/CD.
I believe Rudolph understood my question. Substantially I would like to create my own widgets, upload them (in flash?) and then use them as I can do with the Button.
The reason for this is that I really miss primitives like Arcs and (unfilled) Circles.
I read the documents that you linked but they are not exhaustive and do not explain how to do this.
Is there any reason why BRT is not allowing to create custom widgets?

Yes unfortunately it is not possible to define a widget in this way with EVE to the extent that you would be able to issue custom co-processor commands. I will however suggest this as a feature for future EVE revisions.

Currently the approach to generate custom widgets is to code them individually into custom functions (this is the approach ESD uses) using the inbuilt primitives or co-processor functions. OR as Rudolph has suggested utilise the CMD_NEWLIST / CMD_CALLIST or CMD_APPEND functions.

Best Regards,
BRT Community

6
Discussion - EVE / Re: Widgets
« on: March 06, 2023, 04:54:06 PM »
Hello,

Thank you for your question.

EVE has many in-built widgets which can be utilised by issuing the appropriate co-processor commands to the IC (such as CMD_BUTTON()) for example.
Please see the programmers guide for the full list of widgets:
https://brtchip.com/wp-content/uploads/Support/Documentation/Programming_Guides/ICs/EVE/BRT_AN_033_BT81X_Series_Programming_Guide.pdf

If you require some basics on how the EVE series of ICs can be programmed, please refer to the following application notes:
https://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/EVE/BRT-AN-006-FT81x-Simple-PIC-Example.pdf
https://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/EVE/BRT_AN_008_FT81x_Creating_a_Simple_Library_For_PIC_MCU.pdf

These cover the low level SPI transactions required to interface with EVE and generate displays.

Finally Section 8 and 9 of the following examples application note covers some cases of widget usage:
https://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/EVE/BRT_AN_014_FT81X_Simple_PIC_Library_Examples.pdf

Have you chosen an MCU to use as a SPI master interface yet?
The BRT_AN_025 library is an port of the PIC library from the above application notes, and provides support for a wider range of MCU platforms, you can find the source here:
https://github.com/Bridgetek/EVE-MCU-BRT_AN_025

Best Regards,
BRT Community

7
Discussion - EVE / Re: Disable AUDIO_L output signal
« on: March 02, 2023, 03:26:36 PM »
Hello,

One way is to play the 'silence' sound by writing 0x00 to the REG_SOUND register.

You can find details of the audio playback registers in section 4.7 of the datasheet,
https://brtchip.com/wp-content/uploads/sites/3/2022/04/DS_BT81X-1.1.pdf

Best Regards, BRT Community






8
Discussion - EVE / Re: Reading BT815 font metrics
« on: February 23, 2023, 01:10:15 PM »
Hello,

Thanks for your feedback, we will look into updating the datasheet to make this more clear.

The value listed in datasheet for “font width(max)” row refers to the maximum width value of all ASCII chars listed in the same table of the datasheet.

The font width value for font 28 ‘@’ symbol is 19, which includes the ‘@’ symbol image bitmap width (18 pixel) plus spacing to next char (1 pixel). The bitmap handler will use this value to determine the starting position of next text char in the text string.


Best Regards,
BRT Community

9
Discussion - EVE / Re: Reading BT815 font metrics
« on: February 22, 2023, 03:14:00 PM »
Hello,


I've heard back from he developer on this point:

Code: [Select]
The purpose of width in the width table is to denote the distance to move right when rendering the character.
This includes the character itself, plus the 1-pixel space between characters.
So the widest character can be 18 pixels, with a maximum "width" of 19 pixels.

As such the rom_font.pixel_width is listing the widest character, but not including the 1 pixel spacing. Where as the individual charter widths are listing the widths with the 1 pixel spacing included, as this would be the actual width of the character when displayed on screen.

Best Regards,
BRT Community

10
Discussion - EVE / Re: Simple way to draw meter
« on: February 21, 2023, 01:33:04 PM »
Hi,

Here is one small example of using some gradients along with a gauge widget.

Here is the code and a short description attached,

Code: [Select]
CLEAR_COLOR_RGB(255, 255, 255)
CLEAR(1, 1, 1)

// *** Draw the invisible circles to make the ARC in the stencil buffer ***
COLOR_MASK(0, 0, 0, 1) // Disable writes of R, G and B to the screen
STENCIL_OP(INCR, INCR) // Set the stencil to increment

COLOR_RGB(0, 0, 255)
BEGIN(POINTS)
POINT_SIZE(1600) // Draw an outer circle defining the outside of the arc
VERTEX2II(200, 200)
COLOR_RGB(0, 255, 0)
POINT_SIZE(800) // Draw an inner circle defining the inside of the arc
VERTEX2II(200, 200)
END()

// *** Draw the gradient arc ***
COLOR_MASK(1, 1, 1, 1) // Enable writes to the colors again
STENCIL_OP(KEEP, KEEP) // Stop the stencil INCR
STENCIL_FUNC(EQUAL, 1, 255) // Only draw where the stencil buffer is =1 which is our arc
SCISSOR_SIZE(100, 100) // Constrain drawing to one half of the arc
SCISSOR_XY(100, 100)
CMD_GRADIENT(200, 150, 0xFFFF00, 100, 200, 0xFF0000) // Draw a gradient from red to yellow
SCISSOR_SIZE(100, 100) // Constrain drawing to the other half of the arc
SCISSOR_XY(200, 100)
CMD_GRADIENT(200, 150, 0xFFFF00, 300, 199, 0x00AA00) // Draw a gradient from yellow to green

// *** Return the stencil and scissor to normal***
STENCIL_FUNC(ALWAYS, 1, 255)
SCISSOR_SIZE(800, 480)
SCISSOR_XY(0, 0)

// *** Draw a gauge with no background or tickmarks ***
COLOR_RGB(0, 0, 0)
CMD_GAUGE(200, 200, 107, OPT_NOBACK | OPT_NOTICKS, 4, 8, 32, 100)

Best Regards, BRT Community

11
Discussion - EVE / Re: Reading BT815 font metrics
« on: February 21, 2023, 12:45:44 PM »
Hello Rudolph,

Thankyou for your post.

I've performed a couple of quick tests and can see the font header returning a width of 18 for font 28.
I'm going to chase this up with the development team to see if they have any insight.

Best Regards,
BRT Community

12
Discussion - EVE / Re: Simple way to draw meter
« on: February 20, 2023, 04:54:11 PM »
Hi,

There are a few ways to do this, which can be
- entirely with EVE display objects (including the gauge background and the pointer)
- entirely via loading images (e.g. have a series of bitmap cells with the gauge at different positions)
- or a combination of these (e.g. image as the gauge background and use EVE shapes for the pointer)

One suggested way would be to use an image as the background of the gauge, and then to have a second bitmap of just the pointer and then rotate the pointer image.

You can also make the background using EVE shapes.

We can make a couple of small examples of these for you and post them here.

Best Regards, BRT Community





13
Discussion - EVE / Re: Simple way to draw meter
« on: February 17, 2023, 03:33:30 PM »
Hi,

Is it an arc gauge style which you wish to draw?

Best Regards,
BRT Community


14
Discussion - EVE / Re: Stencils with Fonts
« on: February 09, 2023, 04:38:40 PM »
Hi,

Glad to hear that it helped,

Here is a very rough beta of one way to do highlighting of a block of text and also to do a cursor (by highlighting one character in a similar way)

It needs more testing and optimisation before we publish it officially but hope it helps in the meantime,

The main idea is to get the widths of each character and then add them up to work out where the highlighting rectangle should begin and how wide it should be.

Then, you can draw the rectangle either using a rectangle primitive or via efficient rectangles (see the Gameduino 2 cookbook by James Bowman available on the web as a PDF)

Finally, the text can be placed on top.

The same idea can be used to re-size shapes etc. based on the text within them or if you wanted to write a string and snapshot it etc. or any other case where you need to know the character widths.

This example uses built in fonts but you can also use widths for custom fonts.

In the code, the following lines set which char has the cursor and which chars have the highlight.

   Cursor_Position = 10;

   FirstCharToHighlight = 20;   // highlight 20th-30th characters
   LastCharToHighlight = 30;

The output looks like the attached file,

Best Regards, BRT Community


 
Code: [Select]
   
#define Handle_Highlight 7
#define Handle_Cursor 8

char message[] = "Built-In Font with Highlighting";


// Variables for the built-in font properties
    uint32_t FontByte;
    uint16_t FontIndexCounter;
    uint32_t FontTableAddress = 0;
    uint32_t X = 0;
    uint32_t Y = 0;
#define BuiltInFont 30

    // ###################################################################################################################################
    // Get font properties for a built-in font
    // ###################################################################################################################################

    // ------------------------- Get font properties for a built-in font --------------------
    // This shows how to get the width and properties of internal fonts. We need to read the
    // properties from EVE as the data is not currently in the MCU

    EVE_GPU_FONT_HEADER BuiltInFont_props; // Structure defined in the header file to hold font data

    FontTableAddress = ((HAL_MemRead32(EVE_ROMFONT_TABLEADDRESS)) + ((BuiltInFont-16) * FT_GPU_FONT_TABLE_SIZE));
    // Note that font table starts at font 16
    // EVE_ROMFONT_TABLEADDRESS is equivalent to ROM_FONTROOT
    // Font Table Address = [address at ROM_FONTROOT] + ((font required - 16) * 148)

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

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

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

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

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


    // ###################################################################################################################################
    // Calculate the length of the characters to highlight or to select with cursor
    // ###################################################################################################################################

uint8_t CurrentCharIndex = 0;
volatile char CurrentChar;
volatile uint8_t CurrentCharWidth;
volatile uint8_t CurrentCharHex;
uint32_t MessageSize = (sizeof(message) -1);
uint32_t TotalStringWidth = 0;

// For highlighting a block of text, here we highlight 18th-30th
uint32_t FirstCharXCoord = 0;
uint8_t FirstCharToHighlight = 0;
uint8_t LastCharToHighlight = 0;
uint32_t HighlightStringWidth = 0;
uint8_t Highlight_Enable = 0x00;

// For a cursor highlighting one character, here we select the 10th
uint8_t Cursor_Position = 0; //10
uint8_t CursorCharWidth = 0;
uint32_t CursorCharXCoord = 0;
uint8_t Cursor_Enable = 0x00;


// ######################################## Highlight ##########################################

FirstCharToHighlight = 20; // highlight 20th-30th characters
LastCharToHighlight = 30;

// --------------------- For the highlight -------------------------
// Pass in index to FirstCharToHighlight and LastCharToHighlight
// Provides output of FirstCharXCoord and HighlightStringWidth which are X coordinates to be used to draw a rectangle
CurrentCharIndex = 0;
HighlightStringWidth = 0;
TotalStringWidth = 0;
Highlight_Enable = 0xFF;

// Do not render highlight if values out of range
if((FirstCharToHighlight < 0) || (LastCharToHighlight <= FirstCharToHighlight) )
{
FirstCharXCoord = 0;
HighlightStringWidth = 0;
Highlight_Enable = 0x00;
}
else
{
// Correct any other out of range values
if(FirstCharToHighlight > (MessageSize-1))
{
FirstCharToHighlight =  (MessageSize-1);
}
if(LastCharToHighlight > (MessageSize))
{
LastCharToHighlight =  (MessageSize);
}

do
{
// Sum up the widths of the characters beginning with the first (index 0 in message)
CurrentChar = message[CurrentCharIndex];
CurrentCharHex = (uint8_t) (CurrentChar);
CurrentCharWidth = (uint8_t) BuiltInFont_props.FontWidth[CurrentCharHex];

// Record the total when we reach the START of the highlight. This becomes the width of the string up to the
// left-hand side of the FIRST character to be highlighted, allowing us to work out its coordinate
// Note that the index is 0-based and so 9 would be the 10th character.
if(CurrentCharIndex == FirstCharToHighlight)
{
FirstCharXCoord = TotalStringWidth;
}

// Record the total when we reach the END of the highlight. This becomes the width of the string up to the
// right-hand side of the LAST character to be highlighted, allowing us to work out its coordinate.
if((CurrentCharIndex >= (FirstCharToHighlight)) && (CurrentCharIndex <= (LastCharToHighlight)))
{
HighlightStringWidth += CurrentCharWidth;
}

CurrentCharIndex ++;
TotalStringWidth += CurrentCharWidth;

} while(CurrentCharIndex <= MessageSize);
}


// ######################################## Cursor ##########################################

Cursor_Position = 10;

// --------------------- For the cursor -------------------------
// Pass in index to Cursor_Position
// Provides output of CursorCharXCoord and CursorCharWidth which are X coordinates to be used to draw a rectangle
CurrentCharIndex = 0;
TotalStringWidth = 0;
Cursor_Enable = 0xFF;

// Correct any invalid inputs
if(Cursor_Position < 0)
Cursor_Position = 0;
if(Cursor_Position > MessageSize)
Cursor_Position = MessageSize;

do
{
// Sum up the widths of the characters beginning with the first (index 0 in message)
CurrentChar = message[CurrentCharIndex];
CurrentCharHex = (uint8_t) (CurrentChar);
CurrentCharWidth = (uint8_t) BuiltInFont_props.FontWidth[CurrentCharHex];

// when we reach the selected character where the cursor should go record the values to
// specify where the rectangle should begin and end
if(CurrentCharIndex == Cursor_Position)
{
CursorCharXCoord = TotalStringWidth;
CursorCharWidth = CurrentCharWidth;
}

TotalStringWidth += CurrentCharWidth;
CurrentCharIndex ++;

} while(CurrentCharIndex < MessageSize);


// ###################################################################################################################################
    // Using the font in a display list
    // ###################################################################################################################################


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

X = 50;
Y = 100;

// ----- add a highlight -----

if(Highlight_Enable == 0xFF)
{
// Draw a rectangle using the efficient rectangles method (see Gameduino 2 cookbook), this is for the highlight
EVE_SAVE_CONTEXT(); // Save details such as current color
EVE_BEGIN(EVE_BEGIN_BITMAPS);
EVE_COLOR_RGB(0, 0, 128); // Set a blue color for the highlight
EVE_BITMAP_HANDLE(Handle_Highlight); // Set the handle
EVE_BITMAP_LAYOUT(EVE_FORMAT_L8, 1, 1); // Set an L8 bitmap 1 x 1
EVE_BLEND_FUNC(EVE_BLEND_ONE, EVE_BLEND_ZERO); // Set the blend function
// Set the size of the rectangle to be the width of the area to be highlighted and the height of the font
EVE_BITMAP_SIZE(EVE_FILTER_NEAREST, EVE_WRAP_REPEAT, EVE_WRAP_REPEAT, HighlightStringWidth, BuiltInFont_props.FontHeightInPixels);
EVE_VERTEX2F((X+FirstCharXCoord)*16, Y*16); // Place the top-left of the rectangle at the same coordinate as the character to be highlighted
EVE_RESTORE_CONTEXT(); // Restore the settings such as text colour for the next characters

// You could also use a standard rectangle here instead of the efficient rectangles
//EVE_COLOR_RGB(0, 0, 128); // Set a blue color for the highlight
//EVE_BEGIN(EVE_BEGIN_RECTS);
//EVE_VERTEX2F((X+FirstCharXCoord)*16, Y*16); // Top-left coordinate
//EVE_VERTEX2F((X+FirstCharXCoord + HighlightStringWidth)*16, (Y+BuiltInFont_props.FontHeightInPixels)*16); // Bottom right coordinate
}

// ----- add a cursor -----

if(Cursor_Enable == 0xFF)
{
// Draw a rectangle using the efficient rectangles method, this is for the cursor
// You could also use a standard rectangle here instead
EVE_SAVE_CONTEXT(); // Save details such as current color
EVE_BEGIN(EVE_BEGIN_BITMAPS);
EVE_COLOR_RGB(0, 0, 128); // Set a blue color for the highlight
EVE_BITMAP_HANDLE(Handle_Cursor); // Set the handle
EVE_BITMAP_LAYOUT(EVE_FORMAT_L8, 1, 1); // Set an L8 bitmap 1 x 1
EVE_BLEND_FUNC(EVE_BLEND_ONE, EVE_BLEND_ZERO); // Set the blend function
// Set the size of the rectangle to be the width of the current character and the height of the font
EVE_BITMAP_SIZE(EVE_FILTER_NEAREST, EVE_WRAP_REPEAT, EVE_WRAP_REPEAT, CursorCharWidth, BuiltInFont_props.FontHeightInPixels);
EVE_VERTEX2F((X+CursorCharXCoord)*16, Y*16); // Place the top-left of the rectangle at the same coordinate as the character to be highlighted
EVE_RESTORE_CONTEXT(); // Restore the settings such as text colour for the next characters
}

EVE_BLEND_FUNC(EVE_BLEND_SRC_ALPHA, EVE_BLEND_ONE_MINUS_SRC_ALPHA); // Set the blend function back to default to avoid affecting rest of screen content

EVE_COLOR_RGB(255, 255, 255); // Color white
EVE_CMD_TEXT(X, Y, BuiltInFont, 0, message); // Write the text itself

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

    while(1)
    {
    }

15
Discussion - EVE / Re: Live traking on EVE4
« on: February 08, 2023, 11:22:09 AM »
Hello Elvine314,

Please advise on your previous DM so i can assist you.

Best Regards,
BRT Community

Pages: [1] 2 3 ... 44