Jump to content

Problems with Image and Buttons events


kiwi

Recommended Posts

Hello,

I used the demonstration code for a winButton and added a winImgBox to the layout. This leads to the button being not pressable even though both of them are not overlapping each other. I guess this is no intended behaviour, right? Or there a best practice to avoid this. Sample code is below.

thanks,

kiwi


#include "gfx.h"

static GListener gl;
static GHandle ghButton1, ghImg;
MMCDriver MMCD1;
/* Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).*/
static SPIConfig hs_spicfg = {NULL, GPIOE, GPIOE_PIN4, 0};
/* Low speed SPI configuration (281.250kHz, CPHA=0, CPOL=0, MSb first).*/
static SPIConfig ls_spicfg = {NULL, GPIOE, GPIOE_PIN4,
SPI_CR1_BR_2 | SPI_CR1_BR_1};
/* MMC/SD over SPI driver configuration.*/
static MMCConfig mmccfg = {&SPID4, &ls_spicfg, &hs_spicfg};

static void createWidgets(void) {
GWidgetInit wi;
GImageObject img;

// Apply some default values for GWIN
gwinWidgetClearInit(&wi);
wi.g.show = TRUE;

// Apply the button parameters
wi.g.width = 100;
wi.g.height = 30;
wi.g.y = 80;
wi.g.x = 10;
wi.text = "Push Button";

// Create the actual button
ghButton1 = gwinButtonCreate(0, &wi);

wi.g.show = TRUE;
wi.g.x = 0;
wi.g.y = 0;
wi.g.width = 220;
wi.g.height = 60;
ghImg = gwinImageCreate(&img, &wi.g);
gwinImageOpenFile(ghImg, "logo.gif");
gwinImageCache(ghImg);
gwinShow(ghImg);
}

void ExtraOSInit(void)
{
/* Initialize SDCard */
mmcObjectInit(&MMCD1);
mmcStart(&MMCD1,&mmccfg);
mmcConnect(&MMCD1);
}

int main(void) {
GEvent* pe;
static const orientation_t orients[] = { GDISP_ROTATE_0, GDISP_ROTATE_90, GDISP_ROTATE_180, GDISP_ROTATE_270 };
unsigned which;

// Initialize the display
gfxInit();

// We are currently at GDISP_ROTATE_0
which = 0;
gdispSetOrientation(orients[which]);

// Set the widget defaults
gwinSetDefaultFont(gdispOpenFont("UI2"));
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
gdispClear(White);

// create the widget
createWidgets();

// We want to listen for widget events
geventListenerInit(&gl);
gwinAttachListener(&gl);

while(1) {
// Get an Event
pe = geventEventWait(&gl, TIME_INFINITE);

switch(pe->type) {
case GEVENT_GWIN_BUTTON:
if (((GEventGWinButton*)pe)->gwin == ghButton1) {
// Our button has been pressed
if (++which >= sizeof(orients)/sizeof(orients[0]))
which = 0;

// Setting the orientation during run-time is a bit naughty particularly with
// GWIN windows. In this case however we know that the button is in the top-left
// corner which should translate safely into any orientation.
gdispSetOrientation(orients[which]);
gdispClear(White);
gwinRedrawDisplay(GDISP, FALSE);
}
break;

default:
break;
}
}

return 0;
}

Link to comment
Share on other sites

A few things to check...

1. Does the demo work without the image? The reason to ask this is that setting orientation except at the beginning of a program is officially a no-no. This demo has been limited to give that the best chance of working by restricting all drawing to the smallest dimension box. Even so, it may not work on all hardware as it requires both the touch and display driver to support orientation properly. If the button demo works correctly with the button at its new location then move to step 2.

2. Try your demo without the gwinImageCache call. Caching an image takes a huge amount of memory. It may be slow without it but check correct operation first. If it works without this call it means that caching the image has run you out of memory.

3. Try running your program on one of the emulator platforms. If it runs there but not on your hardware I would suspect that something is crashing on your hardware effectively freezing the program. In this case you will need to get your hardware debugger working and see what is causing the exception. Another way of testing for this would be to also create a gtimer that flashes a led on your board say once a second. If that stops then it has crashed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...