Вы находитесь на странице: 1из 102

Microchip Graphics Library

Architecture

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 1

Welcome to this segment of Microchip Web Seminar series.


My name is Paolo A. Tamayo, an Application Engineer supporting the Graphics
Library and Graphics Applications for PIC24 devices. In this session, I will be
introducing the Microchip Graphics Library Architecture as well as give a basic
example on its usage.

1
Agenda

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 2

The main focus of this presentation is to introduce you to the different components
of the library and give you a first hand look on how to use the library.

2
Agenda

z Library Overview

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 3

First we will take a brief look at the Microchip Library Architecture and give an
overview of each layer.

3
Agenda

z Library Overview
z Graphics Object Layer
z Advanced Graphics Objects

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 4

Next we take a look at the Graphics Object Layer which covers the Advanced
Graphics Objects or commonly known as widgets. These will probably be the most
commonly used items in the library and I would like to give you a brief summary on
the different Objects that the library supports.

4
Agenda

z Library Overview
z Graphics Object Layer
z Advanced Graphics Objects
z Message Interface

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 5

Next we will take a look at the Message Interface that the library provides. This will
introduce how messaging simplifies integration of application, user interface
modules and library components.

5
Agenda

z Library Overview
z Graphics Object Layer
z Advanced Graphics Objects
z Message Interface
z Graphics Library Usage

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 6

We will also take a look at a basic example to give you a jump start on how to use
the library. This will assist you to easily navigate through the documentation and get
you up and running with your application using Microchip’s graphic system solution.

6
Library Overview

Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 7

The Microchip solution starts at the Device Driver Layer.

7
Library Overview

Display Device Driver (DDD)


(i.e. PutPixel, GetPixel)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 8

A single C file implements the most basic functions (ex: PutPixel, GetPixel Set Color) needed to
initialize and use the display device. This is usually through the display device controller.

8
Library Overview

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 9

In some cases, a Graphical Accelerator is implemented in the display controller which performs a
basic rendering function efficiently. This may be enabled by writing to some special registers in
the device controller. This comprises the Device Driver Layer.

9
Library Overview

Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 10

Above the Device Driver Layer is the Graphics Primitive Layer.

10
Library Overview

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 11

This layer calls the basic functions in the Device Driver Layer to render primitive shapes. For
example, a Line function in the Graphics Primitive Layer will call a PutPixel function of the Device
Driver Layer repeatedly with the controlled changes to the x and y positions. Each pixels
identified by the x and y positions will be set to the color chosen for the line.

11
Library Overview

Graphics Objects Layer

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 12

The next layer is the Graphics Object Layer.

12
Library Overview

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 13

In this layer, advanced objects such as Widgets are implemented. This layer also automatically
handles management of objects from creation to destruction. Throughout this session, we will
refer to widgets as Objects.

13
Library Overview
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 14

The library assumes the application layer to contain the modules that initializes and controls the user
interface modules (ex: keypad, touchscreen).

14
Library Overview
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 15

A user interface is provided by the Graphics Object Layer to facilitate easy integration of user
interface modules. This allows the library to be portable to systems with different user interface
modules.

15
Library Overview
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device Driver Layer

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 16

Through the message interface, the application can communicate with the Objects. Together with the
Graphics Object Layer API, applications can now fully integrate the Objects into the application
functions.

16
Library Overview
Application Layer
Application
Mouse Key Pad Touch Screen Specific

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …
Generic
Modules

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device
Device Driver Layer Specific

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 17

We see the three layers of the system. The library integrates some Device Specific and Application
Specific modules and create a solution that is easy to use, and portable.

17
Library Overview
Application Layer
Application
Mouse Key Pad Touch Screen Specific

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …
Generic
Modules

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device
Device Driver Layer Specific

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 18

Furthermore, the application has the facility to directly communicate with any layer of the library.

18
Library Overview
Application Layer
Application
Mouse Key Pad Touch Screen Specific

Graphics Objects Layer Message Interface


FREE

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …
Generic
Modules

Graphics Primitive Functions


(Non-accelerated Line, Circle, Bar, OutText etc)
Graphics Primitives Layer

Display Device Driver (DDD) Graphical Accelerator


(i.e. PutPixel, GetPixel) (Optional)
Device
Device Driver Layer Specific

Graphics Display

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 19

Plus the library is free to use with PIC microcontrollers.

19
Graphics Object Layer
Advanced Graphics Objects (Widgets)

z Button z Edit Box


z Window z List Box
z Check Box z Slider
z Group Box z Scroll Bar
z Radio Button z Progress Bar
z Static Text z Meter
z Image z Dial
z and more….

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 20

The following are the currently supported widgets in the library.

20
Graphics Object Layer

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 21

Here is an example of some widgets implemented in a QVGA display.

21
Graphics Object Layer

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 22

A Image or bitmap is used to render the Microchip Logo.

22
Graphics Object Layer

Rounded
Button

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 23

A rounded button with red color scheme is shown. The green button shows a
pressed state.

23
Graphics Object Layer

Rounded
Button

Circular
Button

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 24

Ten circular buttons are implemented.

24
Graphics Object Layer
Scroll Bar

Rounded
Button

Circular
Button

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 25

Vertical scroll bar is also shown as well as a horizontal scroll bar

25
Graphics Object Layer
Scroll Bar

Check
Box

Rounded
Button

Circular
Button

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 26

Check boxes are shown on the upper right corner.

26
Graphics Object Layer
Scroll Bar
Meter

Check
Box

Rounded
Button

Circular
Button

Image

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 27

And Meters are shown in two modes.

27
Advanced Graphics Object

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 28

Some notable features of the Objects

28
Advanced Graphics Object

z An object can be created, managed and


destroyed using its API’s.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 29

1. API’s are provided to create, control and destroy an Object

29
Advanced Graphics Object

z An object can be created, managed and


destroyed using its API’s.
z Object behavior are determined by its
current state and user action on the object.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 30

2. Object behavior is based on its present state and user action on the Object.

30
Advanced Graphics Object

z An object can be created, managed and


destroyed using its API’s.
z Object behavior are determined by its
current state and user action on the object.
z Objects can be set to inactive or active
state.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 31

3. Objects can be set to active or inactive states.

31
Advanced Graphics Object

z An object can be created, managed and


destroyed using its API’s.
z Object behavior are determined by its
current state and user action on the object.
z Objects can be set to inactive or active
state.
z Objects can be grouped into linked lists.
Performed during object’s creation.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 32

4. Object management is simplified by linked lists. Each newly created object is


added into an active list. Because of this list, drawing of Objects in the display is
performed by the library automatically.

32
Advanced Graphics Object

z An object can be created, managed and


destroyed using its API’s.
z Object behavior are determined by its
current state and user action on the object.
z Objects can be set to inactive or active
state.
z Objects can be grouped into linked lists.
Performed during object’s creation.
z By default, all objects uses a default style
scheme. The style scheme determines the
font table and the color scheme to be used.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 33

5. Style scheme can be implemented in each object. By default an object will be


assigned to use the default style scheme. User can select to create a new style
scheme and assign it to the Object at creation or at any time the Object is
present in memory. The style scheme determines the font table and the color
schemes used to render an Object.

33
Message Interface
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

z For best user experience the user input device must


work cohesively with display
− Simplifies object management from the application point of
view

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 34

The best user experience is achieved when the user input device works cohesively
with the display. This is the reason why the library integrates the basic
management of the Objects based on the user actions.
Benefits derived from this implementation are the following:
1. This simplifies the Object management from the application point of view.

34
Message Interface
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

z For best user experience the user input device must


work cohesively with display
− Simplifies object management from the application point of
view
− The Message Interface layer simplifies integration of user
input device

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 35

2. It simplifies integration of user input devices

35
Message Interface
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

z For best user experience the user input device must


work cohesively with display
− Simplifies object management from the application point of
view
− The Message Interface layer simplifies integration of user
input device
− Support for variety of input devices

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 36

3. It can support a variety of input devices

36
Message Interface
Application Layer
Mouse Key Pad Touch Screen

Graphics Objects Layer Message Interface

Draw Function 1 Draw Function 2 Draw Function N


(i.e. 3D Button) (i.e. Progress Bar) …

z For best user experience the user input device must


work cohesively with display
− Simplifies object management from the application point of
view
− The Message Interface layer simplifies integration of user
input device
− Support for variety of input devices
− Seamless integration with graphics objects

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 37

4. And provides a seamless integration of the input devices with the Objects in the
screen.

37
Graphics Library Usage

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 38

How do we use the library? How easy is it to implement the Objects and use it in
your application?
Let’s take a look at a simple example:

38
Graphics Library Usage

Initialize Graphics
InitGraph()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 39

First InitGraph() is called to reset the display device controller, move the cursor
position to (0, 0) position, and initialize the display to black.

39
Graphics Library Usage

Initialize Graphics
InitGraph()

Create Style Scheme


GolCreateScheme()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 40

Next GOLCreateScheme() is called to define the style scheme used for the
Objects. What is a style scheme? Let’s take a closer look.

40
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct {
WORD EmbossDkColor;
WORD EmbossLtColor;
WORD TextColor0;
WORD TextColor1;
WORD TextColorDisabled;
WORD Color0;
WORD Color1;
WORD ColorDisabled;
WORD CommonBkColor;
char *pFont;
} GOL_SCHEME;

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 41

By default all objects uses a global style scheme structure that defines the font table
used and the color scheme used.

41
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct {
WORD EmbossDkColor;
WORD EmbossLtColor;
WORD TextColor0; Unpressed
WORD TextColor1;
WORD TextColorDisabled;
WORD Color0;
WORD Color1;
WORD ColorDisabled;
WORD CommonBkColor; Pressed
char *pFont;
} GOL_SCHEME;

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 42

Let us take the Button as an example.

42
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct { EmbossDkColor
EmbossLtColor
WORD EmbossDkColor;
WORD EmbossLtColor;
WORD TextColor0; Unpressed
WORD TextColor1;
WORD TextColorDisabled;
WORD Color0;
WORD Color1;
WORD ColorDisabled;
WORD CommonBkColor; Pressed
char *pFont; EmbossDkColor
} GOL_SCHEME;
EmbossLtColor

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 43

To emulate 3 dimensional press effect we interchange the emboss dark and light
color when the object is pressed or released.

43
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct { EmbossDkColor
EmbossLtColor
WORD EmbossDkColor;
WORD EmbossLtColor; TextColor1
WORD TextColor0; Unpressed
WORD TextColor1;
WORD TextColorDisabled;
WORD Color0;
TextColor0
WORD Color1;
WORD ColorDisabled;
WORD CommonBkColor; Pressed
char *pFont; EmbossDkColor
} GOL_SCHEME;
EmbossLtColor

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 44

Also the text color can be changed.

44
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct { EmbossDkColor
EmbossLtColor
WORD EmbossDkColor;
WORD EmbossLtColor; TextColor1
WORD TextColor0; Unpressed
WORD TextColor1;
WORD TextColorDisabled; Color1
WORD Color0;
TextColor0
WORD Color1;
WORD ColorDisabled; Color0
WORD CommonBkColor; Pressed
char *pFont; EmbossDkColor
} GOL_SCHEME;
EmbossLtColor

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 45

As well as the color of the object.

45
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct { EmbossDkColor
EmbossLtColor
WORD EmbossDkColor;
WORD EmbossLtColor; TextColor1
WORD TextColor0; Unpressed
WORD TextColor1;
pFont
WORD TextColorDisabled; Color1
WORD Color0;
TextColor0
WORD Color1;
WORD ColorDisabled; Color0
WORD CommonBkColor; Pressed
char *pFont; EmbossDkColor
} GOL_SCHEME;
EmbossLtColor

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 46

pFont selects the font used in the text.

46
Style Scheme
z By default, all objects uses a global style scheme
structure that defines the font table used and the
color scheme used.
typedef struct { EmbossDkColor
EmbossLtColor
WORD EmbossDkColor;
WORD EmbossLtColor; TextColor1
WORD TextColor0; Unpressed
WORD TextColor1;
pFont
WORD TextColorDisabled; Color1
WORD Color0;
TextColor0
WORD Color1;
WORD ColorDisabled; Color0
WORD CommonBkColor; Pressed
char *pFont; EmbossDkColor
} GOL_SCHEME;
EmbossLtColor

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 47

Common background color is used to hide the object from the screen.
TextColorDisabled and ColorDisabled is used to show that the object is in a
disabled state.

47
Graphics Library Usage

Initialize Graphics
InitGraph()

Create Style Scheme


GolCreateScheme()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 48

If the no changes to the style scheme will be specified, the default style scheme is
used.

48
Graphics Library Usage

Initialize Graphics
InitGraph()
GOL Init()

Create Style Scheme


GolCreateScheme()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 49

In this case, InitGraph() and GOLCreateScheme() functions can be performed by


just one function call to GOL_Init().

49
Graphics Library Usage

Initialize Graphics
InitGraph()
GOL Init()

Create Style Scheme


GolCreateScheme()

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 50

Next step is to create the Objects. ObjCreate( , , ) function represents the multiple
Objects that will be created. This can be a single create function call to create
one Object or a series of calls to different create functions. For example to
create a Button BtnCreate() function is used.

50
Button Example

BUTTON *BtnCreate(
WORD ID,
SHORT
Button
left,top,
right,bottom,
state,
char *pBitmap,
*pText,
GOL_SCHEME *pScheme
)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 51

For example, to create the button, BtnCreate Function is used.

51
Button Example

BUTTON *BtnCreate(
WORD ID,
SHORT
Button
left,top,
right,bottom,
state,
char *pBitmap,
*pText,
GOL_SCHEME *pScheme
)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 52

ID is a user defined number.

52
Button Example

BUTTON *BtnCreate( left, top


WORD ID,
SHORT
Button
left,top,
right,bottom,
right, bottom
state,
char *pBitmap,
*pText,
GOL_SCHEME *pScheme
)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 53

left, top, right & bottom defines the dimension of the object.

53
Button Example

BUTTON *BtnCreate( left, top


WORD ID,
SHORT
Button
left,top,
right,bottom,
right, bottom
state,
char *pBitmap,
*pText,
GOL_SCHEME *pScheme
)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 54

state defines the current state of the Object. For each Object type a defined
state list is used.

54
Button Example

− Button state can be any of the following


#define BTN_FOCUSED 0x0001 // bit for focus state (dotted
// rectangle will be drawn)
#define BTN_PRESSED 0x0002 // bit for press state (button
// is pressed)
#define BTN_DISABLED 0x0010 // bit for enable state
// (disabled button has separate
// colors)
#define BTN_DRAW 0x4000 // bit to indicate button should
// be redrawn
#define BTN_REMOVE 0x8000 // bit to indicate button should
// be removed from screen

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 55

The following list shows the state definition for the button. The way the Button
Object is redrawn on the screen is based on which bit states are set or reset.

BTN_DRAW and BTN_REMOVE are drawing states indicating the objects are to be
refreshed in the display based on the other three state bits: BTN_FOCUSED,
BTN_PRESSED and BTN_DISABLED.

55
Button Example
z To create a button, the
following parameters are
needed: left, top
BUTTON *BtnCreate(
WORD ID,
SHORT Button

left,top,
right,bottom, right, bottom

state,
char *pBitmap,
*pText,
GOL_SCHEME *pScheme
)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 56

pBitmap and pText are set to NULL if no text or bitmap is used. Text is drawn
on top of the bitmap if both are specified. Text drawn on the button face can
be aligned left, right, top or bottom. In the example above we use the word
“Button” as center aligned text.
pScheme – can be user defined or if set to NULL will use the default style
scheme.

56
Button Example
z To create a button, the
following parameters are
needed: left, top
BUTTON *BtnCreate(
WORD ID,
SHORT Button

left,top,
right,bottom, right, bottom

state,
*pBitmap – Set to NULL
char *pBitmap, when not using bitmaps.
*pText,
*pScheme – User defined
GOL_SCHEME *pScheme or set to NULL to use
) default settings.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 57

pBitmap and pText are set to NULL if no text or bitmap is used. Text is drawn
on top of the bitmap if both are specified. Text drawn on the button face can
be aligned left, right, top or bottom. In the example above we use the word
“Button” as center aligned text.
pScheme – can be user defined or if set to NULL will use the default style
scheme.

57
Graphics Library Usage

Initialize Graphics
InitGraph()
GOL Init()

Create Style Scheme


GolCreateScheme()

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 58

After the Objects are created, they are drawn by calling the GOLDraw() function.

58
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme


GolCreateScheme()

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 59

This function parses the active Object’s link list and checks the drawing state of
each of the Objects. If an Object has a pending drawing state set, the Object will
be redrawn. After GOLDraw() renders the Object, it resets the pending drawing
state.

59
Button Example

z To render the Button on the screen call


BtnDraw(pB). Where pB is the pointer to
the Button Object to be rendered.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 60

To render the Button on the screen, BtnDraw(pb) is called where pB is the pointer to
the button object rendered.

60
Button Example

z To render the Button on the screen call


BtnDraw(pB). Where pB is the pointer to
the Button Object to be rendered.
z To manage the state of the Button

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 61

To manage the state of the Button:

61
Button Example

z To render the Button on the screen call


BtnDraw(pB). Where pB is the pointer to
the Button Object to be rendered.
z To manage the state of the Button
SetState(pB, stateBits)
ClrState(pB, stateBits)
GetState(pB, stateBits)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 62

SetState() ClrState() and GetState() are used

62
Button Example

z To render the Button on the screen call


BtnDraw(pB). Where pB is the pointer to
the Button Object to be rendered.
z To manage the state of the Button
SetState(pB, stateBits)
ClrState(pB, stateBits)
GetState(pB, stateBits)
Where stateBits are bits of the state
variable of the Button Object.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 63

where stateBits are the bits of the state variable of the Button object described
earlier.

63
Button Example

Other support APIs

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 64

Other API used to manage the Button are available.

64
Button Example

Other support APIs


z Text management:
− BtnGetText(pB) & BtnSetText(pB,*)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 65

1. Text written over the Object can be modified

65
Button Example

Other support APIs


z Text management:
− BtnGetText(pB) & BtnSetText(pB,*)
z Bitmap management:
− BtnGetBitmap(pB) & BtnSetBitmap(pB, *)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 66

2. Bitmap used can be modified as well.

66
Button Example

Other support APIs


z Text management:
− BtnGetText(pB) & BtnSetText(pB,*)
z Bitmap management:
− BtnGetBitmap(pB) & BtnSetBitmap(pB, *)
z Style Scheme management:
− GetScheme() & SetScheme()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 67

3. Style schemes can be assigned to individual objects. Even objects of the same
type can be assigned different style schemes.

67
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme


GolCreateScheme()

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 68

The next step is to get the user inputs.

68
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme Get User Inputs


GolCreateScheme() Message Struct

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 69

Assume that a user interface module is implemented in the application that sends
messages to the library through the message interface. These messages
contain the user action on the objects in the screen.

69
Messaging

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 70

The library implements the messaging interface

70
Messaging

z Message Structure
typedef struct {
BYTE type;
BYTE event;
SHORT param1;
SHORT param2;
} GOL_MSG;

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 71

using the defined message structure.

71
Messaging

z Message Structure
typedef struct {
BYTE type;
BYTE event;
SHORT param1;
SHORT param2;
} GOL_MSG;
z type is used to determine keypad, touch screen or
pointing device. This also determines how param(n)
are interpreted.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 72

type – defines the device type used. Examples are keypad, touch screen or pointing
devices.

72
Messaging

z Message Structure
typedef struct {
BYTE type;
BYTE event;
SHORT param1;
SHORT param2;
} GOL_MSG;
z type is used to determine keypad, touch screen or
pointing device. This also determines how param(n)
are interpreted.
− Example: Message from touch screen:
− param1 : x position
− param2 : y position

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 73

param1 and param2 – are interpreted based on the type. For the touch screen,
parameters 1 and 2 are defined as the x and y coordinate position respectively.

73
Messaging

z Message Structure
typedef struct {
BYTE type;
BYTE event;
SHORT param1;
SHORT param2;
} GOL_MSG;
z type is used to determine keypad, touch screen or
pointing device. This also determines how param(n)
are interpreted.
− Example: Message from touch screen:
− param1 : x position
− param2 : y position
− For keypad: parameters can be a key code

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 74

For a keypad, key codes are embedded in the parameters.


event – determines the user action

74
Messaging

z event is a generic message of input


device

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 75

Events is also interpreted as the messages specific to the input devices, more
precisely the user action. They are pre-defined and all devices of the same type
should use these messages.

75
Messaging

z event is a generic message of input


device
− event definition for touch screen
− EVENT_PRESS
− EVENT_RELEASE
− EVENT_MOVE

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 76

Events in a touch screen module are defined as:


1. EVENT_PRESS
2. EVENT_RELEASE
3. EVENT_MOVE

76
Messaging

z event is a generic message of input


device
− event definition for touch screen
− EVENT_PRESS
− EVENT_RELEASE
− EVENT_MOVE
− event definition for key board can be
− EVENT_PRESS
− EVENT_RELEASE

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 77

For a keyboard:
• EVENT_PRESS
• EVENT_RELEASE

77
Messaging

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 78

Whenever a message is received by the Object, the Object evaluates if the


message is valid or not.

78
Messaging

z User Action ID
− List of defined actions (or state change) that
an object has accepted.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 79

When the receiving Object evaluated the message to be valid it replies with one of
the defined action ID. The Action ID is a list of defined actions that an object will
accept.

79
Messaging

z User Action ID
− List of defined actions (or state change) that
an object has accepted.
− Each object type has a predefined list.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 80

Each object will have its own list of action IDs.

80
Messaging

z User Action ID
− List of defined actions (or state change) that
an object has accepted.
− Each object type has a predefined list.
− Button Example:
− BTN_MSG_PRESSED
− BTN_MSG_RELEASED

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 81

For the Button example, the two predefined action ID are BTN_MSG_PRESSED
and BTN_MSG_RELEASED.

81
Messaging

z User Action ID
− List of defined actions (or state change) that
an object has accepted.
− Each object type has a predefined list.
− Button Example:
− BTN_MSG_PRESSED
− BTN_MSG_RELEASED

− If object is not affected by the user action it


returns MSG_INVALID.

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 82

If the message is deemed to be invalid, the Object replies with MSG_INVALID. An


example of a returned MSG_INVALID is when an object is set to be inactive. Any
messages to that object will automatically be replied with MSG_INVALID.

82
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme Get User Inputs


GolCreateScheme() Message Struct

Create Objects
ObjCreate(,,)

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 83

The library uses

83
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme Get User Inputs


GolCreateScheme() Message Struct

Create Objects Process User


ObjCreate(,,) Messages
GOLMsg()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 84

GOLMsg() to process these messages and checks the active Object’s link list to
determine which Object will be affected by the message. An optional way to
modify object behavior is also provided. One way is through the message call
back.

84
Message Callback Example

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 85

Here is an example on how messaging is further utilized to customize object


behavior.

85
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

return 1; // Process message by default


}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 86

The GOLMsgCallback() is a function created by the user to add or remove object


control. If no additional controls are to be added it must return 1.

86
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel

case ID_BUTTON1: // if button 1 is pressed

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 87

In this example: there are three objects: WINDOW, BUTTON1 and BUTTON2.

87
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 88

For WINDOW: when touch screen touches the CLIENT area indicated by the
WND_MSG_CLIENT action ID, the pixel on the x,y location is set to red.

88
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 89

After drawing the red pixel, it returns 0 indicating that no further default action will be
processed on the message and the message is discarded.

89
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed


if(objMsg == BTN_MSG_PRESSED) {
BtnSetBitmap(pObj, &duckPressed);
}
if(objMsg == BTN_MSG_RELEASED) {
BtnSetBitmap(pObj, &duckReleased);
}
break;

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 90

For BUTTON1: If the touch screen presses this object as indicated by the
BTN_MSG_PRESSED action ID, the bitmap drawn on the object is changed to
duckPressed.

90
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed


if(objMsg == BTN_MSG_PRESSED) {
BtnSetBitmap(pObj, &duckPressed);
}
if(objMsg == BTN_MSG_RELEASED) {
BtnSetBitmap(pObj, &duckReleased);
}
break;

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 91

When released indicated by the BTN_MSG_RELEASED action ID, the bitmap


drawn is changed to duckReleased.

91
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed


if(objMsg == BTN_MSG_PRESSED) {
BtnSetBitmap(pObj, &duckPressed);
}
if(objMsg == BTN_MSG_RELEASED) {
BtnSetBitmap(pObj, &duckReleased);
}
break;

case ID_BUTTON2:

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 92

To complete the object’s press and release effect we must return 1 and let the
library manage the press and effect rendering of the button.

92
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed


if(objMsg == BTN_MSG_PRESSED) {
BtnSetBitmap(pObj, &duckPressed);
}
if(objMsg == BTN_MSG_RELEASED) {
BtnSetBitmap(pObj, &duckReleased);
}
break;

case ID_BUTTON2:
break; // Do nothing process by default
}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 93

For BUTTON2: there is no action change so we just return 1.

93
Message Callback Example
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {
WORD objectID;
objectID = GetObjID(pObj);

switch(objectID) {
case ID_WINDOW1: // If x,y in client area draw red pixel
if(objMsg == WND_MSG_CLIENT) {
SetColor(RED);
PutPixel(pMsg->param1,pMsg->param2);
}
return 0; // Don’t process by default

case ID_BUTTON1: // if button 1 is pressed


if(objMsg == BTN_MSG_PRESSED) {
BtnSetBitmap(pObj, &duckPressed);
}
if(objMsg == BTN_MSG_RELEASED) {
BtnSetBitmap(pObj, &duckReleased);
}
break;

}
return 1; // Process message by default
}
© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 94

In fact if there is no action change needed we can remove this case in the switch.
Library will manage BUTTON2 for you.

94
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme Get User Inputs


GolCreateScheme() Message Struct

Create Objects Process User


ObjCreate(,,) Messages
GOLMsg()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 95

After the messages are processed

95
Graphics Library Usage

Initialize Graphics Draw Objects


InitGraph() GOLDraw()
GOL Init()

Create Style Scheme Get User Inputs


GolCreateScheme() Message Struct

Create Objects Process User


ObjCreate(,,) Messages
GOLMsg()

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 96

GOLDraw() is again called to redraw the Objects. Thus completing the cycle.

96
Summary

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 97

To summarize we have seen that

97
Summary

z Structure of Microchip’s Graphics


Library

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 98

The Microchip Graphics Library structure allows easy integration of user interface
devices, and display devices.

98
Summary

z Structure of Microchip’s Graphics


Library
z Modular solution allows easy application
migration to different display hardware

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 99

The modular solution allows easy migration from one display platform to another.

99
Summary

z Structure of Microchip’s Graphics


Library
z Modular solution allows easy application
migration to different display hardware
z How to use the library

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 100

You have seen the simple usage of the library and with a small code integrate it into
your application.

100
Summary

z Structure of Microchip’s Graphics


Library
z Modular solution allows easy application
migration to different display hardware
z How to use the library
z Microchip Graphic Library Source code
and API Manual is freely downloadable
from www.microchip.com/graphics

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 101

This is a free graphics library solution for PIC microcontrollers. For source code and
API manual please go to www.microchip.com/graphics

101
THANK YOU

© 2007 Microchip Technology Incorporated. All Rights Reserved. Microchip Graphics Library Architecture Slide 102

102

Вам также может понравиться