Jump to content

Forcing pushbuttons image


ForTest

Recommended Posts

You can change the image of a pushbutton (presuming that you use the built-in image rendering function) at any time by calling gwinSetCustomDraw() passing a pointer to a different image as the custom parameter.

However, I assume that you talk about the state of the button (the different images for the three states "enabled", "disabled" and "pressed" which are just one image file). Using a pushbutton widget without GINPUT/GEVENT doesn't make much sense and is actually impossible (it won't even compile!). Can you please be more specific?

Link to comment
Share on other sites

I'd like to switch between images (normal button and pressed button) when a specific button is pressed

I want to use my set of routine for manage the events, so i need to change the image of the pressed and released button by my code

A single image (normal button) is size 50x49, so i've merged the two images in a single file size 50 x 98

Is there a way to switch between the two images in a similar way that you do with your GINPUT/GEVENT mode ? (i mean programmatically)

It's clear to me the way to switch between two different images (size 50x49), but i was wondering if there was the possibility to use a single image file

 

/******************************************************************************/
/* This file has been generated by the uGFX-Studio                            */
/*                                                                            */
/* http://ugfx.org                                                            */
/******************************************************************************/

#include "colors.h"
#include "widgetstyles.h"
#include "gui.h"

// GListeners
GListener glistener;

// GHandles
GHandle ghContainerPage0;
GHandle ghARROW_UP;

// Fonts
font_t dejavu_sans_16;

// Images
gdispImage ARROW_UP_50x98;

static void createPagePage0(void)
{
	GWidgetInit wi;
	gwinWidgetClearInit(&wi);


	// create container widget: ghContainerPage0
	wi.g.show = FALSE;
	wi.g.x = 0;
	wi.g.y = 0;
	wi.g.width = 800;
	wi.g.height = 480;
	wi.g.parent = 0;
	wi.text = "Container";
	wi.customDraw = 0;
	wi.customParam = 0;
	wi.customStyle = 0;
	ghContainerPage0 = gwinContainerCreate(0, &wi, 0);

	// create button widget: ghARROW_UP
	wi.g.show = TRUE;
	wi.g.x = 350;
	wi.g.y = 200;
	wi.g.width = 50;
	wi.g.height = 49;
	wi.g.parent = ghContainerPage0;
	wi.text = "";
	wi.customDraw = gwinButtonDraw_Image;
	wi.customParam = &ARROW_UP_50x98;
	wi.customStyle = 0;
	ghARROW_UP = gwinButtonCreate(0, &wi);
}

void guiShowPage(unsigned pageIndex)
{
	// Hide all pages
	gwinHide(ghContainerPage0);

	// Show page selected page
	switch (pageIndex) {
	case 0:
		gwinShow(ghContainerPage0);
		break;

	default:
		break;
	}
}

void guiCreate(void)
{
	GWidgetInit wi;

	// Prepare fonts
	dejavu_sans_16 = gdispOpenFont("DejaVuSans16");

	// Prepare images
	gdispImageOpenFile(&ARROW_UP_50x98, "rsc/ARROW_UP_50x98.bmp");

	// GWIN settings
	gwinWidgetClearInit(&wi);
	gwinSetDefaultFont(dejavu_sans_16);
	gwinSetDefaultStyle(&white, FALSE);
	gwinSetDefaultColor(black_studio);
	gwinSetDefaultBgColor(white_studio);

	// Create all the display pages
	createPagePage0();

	// Select the default display page
	guiShowPage(0);

}

void guiEventLoop(void)
{
	GEvent* pe;

	while (1) {
		// Get an event
		pe = geventEventWait(&glistener, 0);
		switch (pe->type) {
		}

	}
}
 

 

Edited by ForTest
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...