See changelog v0.9.8
[hackover2013-badge-firmware.git] / project / commands / drawing / cmd_button.c
1 /**************************************************************************/
2 /*!
3 @file cmd_buton.c
4 @author K. Townsend (microBuilder.eu)
5
6 @brief Code to execute for cmd_button in the 'core/cmd'
7 command-line interpretter.
8
9 @section LICENSE
10
11 Software License Agreement (BSD License)
12
13 Copyright (c) 2010, microBuilder SARL
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 1. Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23 3. Neither the name of the copyright holders nor the
24 names of its contributors may be used to endorse or promote products
25 derived from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
28 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /**************************************************************************/
39 #include <stdio.h>
40 #include <string.h>
41
42 #include "projectconfig.h"
43 #include "core/cmd/cmd.h"
44 #include "project/commands.h" // Generic helper functions
45
46 #ifdef CFG_TFTLCD
47 #include "drivers/displays/tft/lcd.h"
48 #include "drivers/displays/tft/drawing.h"
49 #include "drivers/displays/tft/touchscreen.h"
50 #include "drivers/displays/tft/fonts/dejavusans9.h"
51
52 /**************************************************************************/
53 /*!
54 Displays a button on the LCD with or without text.
55
56 Ex.: "btn 10 10 220 35 1 This is a test" will display a 220x35 pixel
57 button in the 'pressed' state (arg 5 = 1) starting at pixel 10, 10 with
58 'This is a test' rendered on the button.
59 */
60 /**************************************************************************/
61 void cmd_button(uint8_t argc, char **argv)
62 {
63 int32_t x, y, w, h, border, fill, font;
64
65 // ToDo: Validate data!
66
67 // Convert supplied parameters
68 getNumber (argv[0], &x);
69 getNumber (argv[1], &y);
70 getNumber (argv[2], &w);
71 getNumber (argv[3], &h);
72 getNumber (argv[4], &border);
73 getNumber (argv[5], &fill);
74 getNumber (argv[6], &font);
75
76 if (argc == 7)
77 {
78 // Render the button with no text
79 drawButton(x, y, w, h, &dejaVuSans9ptFontInfo, 7, (uint16_t)border, (uint16_t)fill, (uint16_t)font, NULL);
80 }
81 else
82 {
83 // Get text contents
84 uint8_t i, len, *data_ptr, data[50];
85 data_ptr = data;
86 for (i = 0; i < argc - 7; i++)
87 {
88 len = strlen(argv[i + 7]);
89 strcpy((char *)data_ptr, (char *)argv[i + 7]);
90 data_ptr += len;
91 *data_ptr++ = ' ';
92 }
93 *data_ptr++ = '\0';
94
95 // Render the button with text
96 drawButton(x, y, w, h, &dejaVuSans9ptFontInfo, 7, (uint16_t)border, (uint16_t)fill, (uint16_t)font, (char *)&data);
97 }
98 }
99
100 #endif
This page took 0.057067 seconds and 5 git commands to generate.