Merge branch 'master' of git://github.com/microbuilder/LPC1343CodeBase
[hackover2013-badge-firmware.git] / project / commands / drawing / cmd_rectangle.c
1 /**************************************************************************/
2 /*!
3 @file cmd_rectangle.c
4 @author K. Townsend (microBuilder.eu)
5
6 @brief Code to execute for cmd_rectangle 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
41 #include "projectconfig.h"
42 #include "core/cmd/cmd.h"
43 #include "project/commands.h" // Generic helper functions
44
45 #ifdef CFG_TFTLCD
46 #include "drivers/displays/tft/lcd.h"
47 #include "drivers/displays/tft/drawing.h"
48
49 /**************************************************************************/
50 /*!
51 Displays a rectangle on the LCD.
52 */
53 /**************************************************************************/
54 void cmd_rectangle(uint8_t argc, char **argv)
55 {
56 int32_t x1, y1, x2, y2, c, filled, border;
57 filled = 0;
58
59 // Convert supplied parameters
60 getNumber (argv[0], &x1);
61 getNumber (argv[1], &y1);
62 getNumber (argv[2], &x2);
63 getNumber (argv[3], &y2);
64 getNumber (argv[4], &c);
65 if (argc >= 6)
66 {
67 getNumber (argv[5], &filled);
68 }
69 if (argc == 7)
70 {
71 getNumber (argv[6], &border);
72 if (border < 0 || border > 0xFFFF)
73 {
74 printf("Invalid Border Color%s", CFG_PRINTF_NEWLINE);
75 return;
76 }
77 }
78
79 // ToDo: Validate data!
80 if (c < 0 || c > 0xFFFF)
81 {
82 printf("Invalid Color%s", CFG_PRINTF_NEWLINE);
83 return;
84 }
85
86 if (filled)
87 drawRectangleFilled(x1, y1, x2, y2, (uint16_t)c);
88 else
89 drawRectangle(x1, y1, x2, y2, (uint16_t)c);
90
91 if (argc == 7)
92 {
93 drawRectangle(x1, y1, x2, y2, (uint16_t)border);
94 }
95 }
96
97 /**************************************************************************/
98 /*!
99 Displays a rectangle with rounded corners on the LCD.
100 */
101 /**************************************************************************/
102 void cmd_rectangleround(uint8_t argc, char **argv)
103 {
104 int32_t x1, y1, x2, y2, c, radius, corners, filled, border;
105 filled = 0;
106
107 // Convert supplied parameters
108 getNumber (argv[0], &x1);
109 getNumber (argv[1], &y1);
110 getNumber (argv[2], &x2);
111 getNumber (argv[3], &y2);
112 getNumber (argv[4], &c);
113 getNumber (argv[5], &radius);
114 getNumber (argv[6], &corners);
115 if (argc >= 8)
116 {
117 getNumber (argv[7], &filled);
118 }
119 if (argc == 9)
120 {
121 getNumber (argv[8], &border);
122 if (border < 0 || border > 0xFFFF)
123 {
124 printf("Invalid Border Color%s", CFG_PRINTF_NEWLINE);
125 return;
126 }
127 }
128
129 // ToDo: Validate data!
130 if (c < 0 || c > 0xFFFF)
131 {
132 printf("Invalid Color%s", CFG_PRINTF_NEWLINE);
133 return;
134 }
135
136 if (filled)
137 drawRoundedRectangleFilled(x1, y1, x2, y2, (uint16_t)c, radius, corners);
138 else
139 drawRoundedRectangle(x1, y1, x2, y2, (uint16_t)c, radius, corners);
140
141 // Draw border if it's not the same color
142 if (argc == 9)
143 {
144 drawRoundedRectangle(x1, y1, x2, y2, (uint16_t)border, radius, corners);
145 }
146 }
147
148 #endif
This page took 0.057712 seconds and 5 git commands to generate.