我对hello_widget这个项目做了适当的修改
//*****************************************************************************
//
// Forward reference to various widget structures.
//
//*****************************************************************************
extern tCanvasWidget g_sBackground;
extern tCanvasWidget g_sTop;
extern tCanvasWidget g_sMi;
extern tPushButtonWidget g_sPushBtn;
//*****************************************************************************
//
// Forward reference to the button press handler.
//
//*****************************************************************************
void OnButtonPress(tWidget *pWidget);
//*****************************************************************************
//
// The heading containing the application title.
//
//*****************************************************************************
//
//define the back ground on the top of the LCD as a canvas
//
Canvas( g_sBackground,
WIDGET_ROOT,
0,&g_sTop,
&g_sKitronix320x240x16_SSD2119,
0,0,0,0,
(CANVAS_STYLE_FILL|CANVAS_STYLE_OUTLINE),
ClrBurlyWood,ClrRed,
0,0,0,0,0);
//
//define the word on the top of the LCD as a canvas
//
Canvas( g_sTop,
&g_sBackground,
0,&g_sPushBtn,
&g_sKitronix320x240x16_SSD2119,
0,0,0,0,
(CANVAS_STYLE_TEXT|CANVAS_STYLE_TEXT_HCENTER|CANVAS_STYLE_TEXT_OPAQUE),
ClrBurlyWood,0,ClrRed,&g_sFontCm20i,"hello-widget",0,0);
//
//define a widget for the button
//
RectangularButton( g_sPushBtn,
&g_sTop,
0,0,
&g_sKitronix320x240x16_SSD2119,
0,0,0,0,
(PB_STYLE_FILL|PB_STYLE_OUTLINE|PB_STYLE_RELEASE_NOTIFY|PB_STYLE_TEXT|PB_STYLE_TEXT_OPAQUE),
ClrBurlyWood,
ClrCoral,
ClrWhite,
ClrRed,
&g_sFontCm20i,
"Show Hello!",
0,0,0,0,OnButtonPress);
//
//define the cave for the Hello word
//
Canvas( g_sMi,
&g_sPushBtn,
0,0,
&g_sKitronix320x240x16_SSD2119,
0,0,0,0,
(CANVAS_STYLE_TEXT|CANVAS_STYLE_TEXT_HCENTER|CANVAS_STYLE_TEXT_OPAQUE),
0,0,ClrWhite,&g_sFontCm32,"Hello,world!",0,0);
tBoolean g_bHelloVisible = false;
void
OnButtonPress(tWidget *pWidget)
{
g_bHelloVisible = !g_bHelloVisible;
if(g_bHelloVisible)
{
//
// Add the Hello widget to the tree as a child of the push
// button. We could add it elsewhere but this seems as good a
// place as any. It also means we can repaint from g_sPushBtn and
// this will paint both the button and the welcome message.
//
WidgetAdd((tWidget *)&g_sPushBtn, (tWidget *)&g_sMi);
//
// Change the button text to indicate the new function.
//
PushButtonTextSet(&g_sPushBtn, "Hide Welcome");
//
// Repaint the pushbutton and all widgets beneath it (in this case,
// the welcome message).
//
WidgetPaint((tWidget *)&g_sPushBtn);
}
else
{
//
// Remove the Hello widget from the tree.
//
WidgetRemove((tWidget *)&g_sMi);
//
// Change the button text to indicate the new function.
//
PushButtonTextSet(&g_sPushBtn, "Show Welcome");
//
// Repaint the widget tree to remove the Hello widget from the
// display. This is rather inefficient but saves having to use
// additional widgets to overpaint the area of the Hello text (since
// disabling a widget does not automatically erase whatever it
// previously displayed on the screen).
//
WidgetPaint(WIDGET_ROOT);
}
}
int main(void)
{
tContext sContext;
//
//set the clock for arm
//
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
//Enable pins
//
PinoutSet();
//
//Init the LCD
//
Kitronix320x240x16_SSD2119Init();
//
//Init the sContext
//
GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);
//
// Enable Interrupts
//
IntMasterEnable();
//
// Initialize the touch screen driver.
//
TouchScreenInit();
//
// Set the touch screen event handler.
//
TouchScreenCallbackSet(WidgetPointerMessage);
//
// Add the compile-time defined widgets to the widget tree.
//
g_sBackground.sBase.sPosition.sXMax =GrContextDpyWidthGet(&sContext);
g_sBackground.sBase.sPosition.sYMax =(GrContextDpyHeightGet(&sContext))/10;
g_sTop.sBase.sPosition.sXMax =GrContextDpyWidthGet(&sContext);
g_sTop.sBase.sPosition.sYMax =GrContextDpyHeightGet(&sContext)/10;
g_sPushBtn.sBase.sPosition.sXMin =GrContextDpyWidthGet(&sContext)/5;
g_sPushBtn.sBase.sPosition.sYMin =GrContextDpyHeightGet(&sContext)/4;
g_sPushBtn.sBase.sPosition.sXMax =GrContextDpyWidthGet(&sContext)*4/5;
g_sPushBtn.sBase.sPosition.sYMax =GrContextDpyHeightGet(&sContext)/2;
g_sMi.sBase.sPosition.sXMin =GrContextDpyWidthGet(&sContext)/5;
g_sMi.sBase.sPosition.sYMin =GrContextDpyHeightGet(&sContext)*6/10;
g_sMi.sBase.sPosition.sXMax =GrContextDpyWidthGet(&sContext)*4/5;
g_sMi.sBase.sPosition.sYMax =GrContextDpyHeightGet(&sContext)*9/10;
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
//
// Paint the widget tree to make sure they all appear on the display.
//
WidgetPaint(WIDGET_ROOT);
//
// Loop forever, processing widget messages.
//
while(1)
{
//
// Process any messages from or for the widgets.
//
WidgetMessageQueueProcess();
}
}
但是在我按键让hello消失的时候,无法消失,这是为什么呢?麻烦路过的大哥帮帮忙!
此帖出自
小平头技术问答
一周热门 更多>