This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430F5659:图形库 GrLib 帮助

Guru**** 2535150 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/808418/ccs-msp430f5659-help-with-graphics-library-grlib

器件型号:MSP430F5659

工具/软件:Code Composer Studio

您好!

我正在使用 TI 图形库、想知道熟悉例程的人是否可以帮助我修改 DrawButton 命令。

当前该命令要求按钮中文本开头的 x、y 坐标、但结果当然会因字符串的字体和长度而异。 很高兴让常规的自动将代码置于框中的中心、因为它知道框坐标。 有一个 DrawStringCentered 例程作为一个单独的函数、但我不能轻易地确定如何实现它。 我们非常感谢 Ant 的帮助。 以下是 drawButton 的代码;

谢谢、

Jerry

//
//
//! 绘制一个按钮。
//!
//! \param 上下文是要使用的绘图上下文的指针。
//! \param 按钮是指向包含扩展名的结构的指针
//! 按钮。
//!
//! 此函数绘制一个按钮。 该按钮将包含一个文本字符串、并且将
//! 基于在 Button 结构中传递的参数创建。
//!
//! \无返回。
//
//
void Graphics_drawButton (const Graphics_context *上下文、
const Graphics_Button *按钮)
{unsigned int colorb1;
uint32_t origFrgnd = g_sContext.for前景;
Graphics_Font * origFont =(Graphics_Font *) g_sContext.font;

graphics_Rectangle borderRect ={
button->xMin、
button->yMin、
button->Xmax、
button->yMax、
};

graphics_Rectangle innerRect ={
button->xMin + button->borderWidth、
button->yMin + button->borderWidth、
button->Xmax - button->borderWidth、
button->yMax - button->borderWidth、
};


graphics_setForegroundColor (&G) sContext、button->bordercolor);
//colorb1=Graphics_button *button->bordercolor;
// w_recb (button->xMin-3、button->yMin+1、button->Xmax-button->xMin+8、button->yMax-button->yMin+1、黑色、红色);//新边框
graphics_fillRectangle (&g_sContext、&borderRect);

if (button->selected){
graphics_setForegroundColor (&G) sContext、button->SelectedColor);
}否则{
graphics_setForegroundColor (&G) sContext、button->fillColor);

graphics_fillRectangle (&g_sContext、innerRect);

graphics_setFont (&g_sContext、button->font);

if (button->selected){
graphics_setForegroundColor (&G) sContext、button->selectedTextColor);
}否则{
graphics_setForegroundColor (&G) sContext、button->textColor);

graphics_drawstring (&g_sContext、
按钮->文本,
AUTO_STRING_LENGTH、
button->textXPos、
button->textYPos、
Transparent_text);

graphics_setFont (&g_sContext、origFont);
graphics_setForegroundColor (&g_sContext、origFrgnd);

 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Jerry、

    我将对此进行研究、并将很快提供更新。

    谢谢、

    Mitch

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Jerry、

    很抱歉耽误您的时间-这实际上是我第一次深入到我们的图形库中。 我更改了一些示例代码、并在我的末尾得到了一些有效的东西 我更改了 button.c 中的以下内容:

    void Graphics_drawButton (const Graphics_context *上下文、
    const Graphics_Button *按钮)
    {
    uint32_t origFrgnd = g_sContext.foreet;
    Graphics_Font * origFont =(Graphics_Font *) g_sContext.font;
    
    Graphics_Rectangle borderRect ={
    button->xMin、
    button->yMin
    、button->yMin、button->yMax、button
    、button->yMin、button、button、}
    
    
    graphics_Rectangle innerRect ={
    button->xMin + button->borderWidth、
    button->yMin + button->borderWidth、
    button->Xmax - button->borderWidth、
    button->yMax - button->borderWidth、
    };
    
    
    Graphics_setForegroundColor (&G) sContext、button->bordercolor);
    Graphics_fillRectangle (&G) sContext、&borderRect);
    
    if (button->selected){
    Graphics_setForegroundColor (&G)、button->SelectedColor);
    否则{
    Graphics_setForegroundColor (&charge-Text)
    }
    
    Graphics_fillRectangle (&g_sContext、&innerRect);
    
    Graphics_setFont (&g_sContext、button->font);
    
    if (button->selected){
    Graphics_setForegroundColor (&g_sContext、button->selectedTextColor);
    否则{Graphics_setForegoundColor
    (&g_Context-text
    )};text_text_TextColor}
    graphics_drawStringCenter(&G sContext,
    button->Text,
    AUTO_STRING_LENGTH,
    (button->Xmax - button->xMin)/2,
    (button->yMax - button->yMin)/2,
    Transparenty_text);
    
    Graphics_setFont (&g_sContext、origFont);
    Graphics_setForegroundColor (&g_sContext、origFrgnd);
    } 

    我为"Graphics_drawStringCenter"函数切换了原始的"Graphics_drawstring"函数。 我在该函数中输入"居中" x 和 y 坐标、方法是取最大值和最小值的差值并除以2。  

    就是这样! 请告诉我这是否适用于您的目的

    谢谢、

    Mitch