GUI abstraction

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

GUI abstraction

Postby Tectu » Tue Jun 26, 2012 10:28 am

Hello Folks,

I just reimplemented the whole GUI abstraction layer.
Before it was like this: You call guiInit(); which does continiously read out the touchpad coordinates. Then, when you call guiDrawButton(), a new thread is created which does read the variables provided by the GUI main thread. If these coordinates are inside the button's area, the variable you specified is set to 1, otherwise to 0.
The problem is that this does need a massive amount of memory and CPU resources. If you have 10 buttons, you have 11 threads, each with its own working area!

The current implemenetation works as following: You call guiInit(); once. As a parameter, you give it an update interval in milliseconds. Then, whenever you can guiDrawButton(), the button is inserted into a linked list. The GUI thread created when calling guiInit() does now walk through the linked list. It first checks if the button is set to active. If not, it ignores it and goes to the next linked list entry. Otherwise, it will look if the coordinates read out from the touchpad are inside the button area and does set the given variable to 1, otherwise to 0. Between taking the next list element, the thread sleeps for the amount of milliseconds you specified with the interval parameter from guiInit().

Here's the guiDrawButton Prototype:

Code: Select all

uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *active, uint8_t *state)


And here some simple usage example:

Code: Select all

    uint8_t setActive, setState, clearActive, clearState;

    setActive = active;
    clearActive = active;
    //setActive = inactive;
    //clearActive = inactive;

    guiInit(10);
    guiDrawButton(10, 10, 60, 60, "Set", Black, Yellow, &setActive, &setState);
    guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, &clearActive, &clearState);
       
    while (TRUE) {
        if(setState)
            palSetPad(GPIOD, GPIOD_LED3);
        if(clearState)
            palClearPad(GPIOD, GPIOD_LED3);
           
        chThdSleepMilliseconds(200);   
    }


I am open for any ideas, improvements, critics or something else :)


~ Tectu

Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm
Location: India

Re: GUI abstraction

Postby Abhishek » Tue Jun 26, 2012 11:16 am

A head start for the GUI project!

Let's keep the good work going..

Abhishek

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: GUI abstraction

Postby Tectu » Tue Jun 26, 2012 9:01 pm

Yeah, I'll definitly keep working on a GUI abstraction.

I also added an example how to use the GUI in the demos folder.


~ Tectu

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: GUI abstraction

Postby Tectu » Wed Jun 27, 2012 8:20 am

I made now a new branch, called 'gui'. I will keep the latest work of the GUI abstraction layer in there. This way, we keep a merge-able and stable master.

I just implementet some shadowing for the buttons. You can specify the width of the shadow in pixels when calling guiDrawButton()

http://www.abload.de/img/20120627_0932278c5en.jpg
http://www.abload.de/img/20120627_094036z3yt2.jpg

~ Tectu

mobyfab
Posts: 483
Joined: Sat Nov 19, 2011 6:47 pm
Location: Le Mans, France
Has thanked: 21 times
Been thanked: 30 times

Re: GUI abstraction

Postby mobyfab » Fri Jun 29, 2012 11:11 am

Looks great, good job. :)

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: GUI abstraction

Postby Tectu » Fri Jun 29, 2012 11:15 am

Thank you very much :)
As next feature, I'll implement some feancy pressed animation. I guess I'll do it as #ifdef so we can go with #define LCD_USE_ANIMATIONS or something else so we can turn of some heavy calculation stuff.


~ Tectu

miguelmoreto
Posts: 15
Joined: Thu Jun 28, 2012 9:21 pm
Location: Brazil
Contact:

Re: GUI abstraction

Postby miguelmoreto » Fri Jul 06, 2012 4:43 am

Hello Tectu,

how can I use the guiDrawButton function?

The example code at demo folder is not working because guiDrawButton now has several more arguments.

Do you have an example of usage of this new implementation of guiDrawButton?

I don't know how use the "font" arguments of type "font_t".

Best regards.

Miguel

Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm
Location: India

Re: GUI abstraction

Postby Abhishek » Fri Jul 06, 2012 4:54 am

Hello,

The lib has 3 fonts for rendering textï½ - font_MediumBold, font_Small, font_Larger and there's also a font_LargeNumbers which supports numerals only. Pass one of those to the font argument.

font_t is just an alias for const uint8_t* .

For shadow, I guess you use a value of 4 or 5, should be OK.

Abhishek

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: GUI abstraction

Postby Tectu » Sun Jul 08, 2012 8:07 pm

@miguelmoreto:
I am very sorry that the current GUI implementation isn't up-to-date to the documentation and the sample. The problem was that I had no internet for a week and I couldn't update the wiki.

I did update the wiki right now. There's also a new example in the repo.
The wikipage should explain everything. Please ask if you have any more questions.


~ Tectu

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: GUI abstraction

Postby Tectu » Mon Jul 09, 2012 7:52 pm

Just had a few minutes of spare time. I did implement guiDrawSlider().

Video: http://www.youtube.com/watch?v=qzA1KsB3vEU&feature=g-upl

When calling guiDrawSlider() you can specify if it shall be a passive or an active slider. Passive means it updates the value you pass as an argument (uint8_t *value). Active means it updates it's value when you press the touchpad area inside the slider and then it writes the current value back to the uint8_t *value.
The value is always in percents, from 0 to 100.

The video also shows how to connect an active to a passive slider.

It's just a first implementation.


~ Tectu


Return to “LCD Driver and Graphic Framework”

Who is online

Users browsing this forum: No registered users and 7 guests