Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Commit 8942922

Browse files
authored
Merge pull request #4 from SpencerJ21/scaling
Scaling
2 parents ab97496 + b6189ca commit 8942922

File tree

6 files changed

+202
-90
lines changed

6 files changed

+202
-90
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ bin/
44

55
compile_commands.json
66
temp.log
7+
8+
*.zip

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ USE_PACKAGE:=0
2323
IS_LIBRARY:=1
2424
# TODO: CHANGE THIS!
2525
LIBNAME:=screenlib
26-
VERSION:=1.0.0
26+
VERSION:=1.0.1
2727
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
2828
# this line excludes opcontrol.c and similar files
2929
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/opcontrol $(SRCDIR)/initialize $(SRCDIR)/autonomous,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))
3030

3131
# files that get distributed to every user (beyond your source archive) - add
3232
# whatever files you want here. This line is configured to add all header files
3333
# that are in the the include directory get exported
34-
TEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp
34+
TEMPLATE_FILES=$(INCDIR)/screen/**/*.h $(INCDIR)/screen/**/*.hpp
3535

3636
.DEFAULT_GOAL=quick
3737

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Version
1717
=======
1818
The first digit refers to the vex game: Tower Takeover will be version 1.X.X, while next year's game will be 2.X.X
1919
The second digit refers to any new features that may be added.
20-
The third digit refers to any bug fixes.
20+
The third digit refers to any bug fixes or minor improvements to existing features.
2121

2222
License
2323
=======
@@ -55,13 +55,12 @@ Alternatively, macros can be used for more verbose code; here is the equivalent
5555
`field.draw(screen::cubeGroup::right4, CUBE_HIGHEST + CUBE_2LOWEST);`
5656

5757
`CUBE_HIGHEST` represents the highest cube in the stack, followed by `CUBE_2HIGHEST` (the 2nd highest), followed by `CUBE_2LOWEST` (the 2nd lowest), and finally `CUBE_LOWEST`
58-
As the 4 cube stacks on the left and right are in the same order but slightly different positions, the corresponding cubes are represented the same (purple to purple, orange to orange, green to green)
5958

6059
`CUBE_FAR` and `CUBE_NEAR` are for the cube sectors farLeft and farRight
6160

6261
`CUBE_TOP_NEAR`, `CUBE_FAR_LEFT`, `CUBE_NEAR_LEFT`, `CUBE_FAR_RIGHT`, and `CUBE_NEAR_RIGHT` are used for the five cube stack on the near side
6362

64-
and finally, all macros starting with `TOWER_CUBE_` refer to the cubes around a tower
63+
and finally, all macros starting with `TOWER_CUBE_` refer to the cubes around a tower
6564

6665
Scored Cubes
6766
------------
@@ -70,6 +69,12 @@ Scored cubes are drawn along with where they are, either in a tower or a scoring
7069
a third parameter is used to display "stack height", a number printed on top to describe how many cubes are in the stack.
7170
Note: use `screen::color::none` to abstain from printing a scored cube in that position
7271

72+
Other
73+
-----
74+
The field can be repositioned with `setX`, `setY`, or `setPos`.
75+
and can be resized using `setSideLength`
76+
when changing size, if you are unsatisfied with the numbers printed on the cubes, you can modify the `NumberConfig`, which is given as the 4th parameter in the constructor. More information is available in [field.hpp](./include/field.hpp)
77+
7378
Example
7479
-------
7580
This directory (specifically [opcontrol.cpp](./src/opcontrol.cpp)) is a usage example (it produces the image at the top of this page)
@@ -78,4 +83,4 @@ Acknowledgements
7883
================
7984
smallfont.c is converted version of the digits 0-9 from [Synchronizer NBP Font](https://www.fontspace.com/total-fontgeek-dtf-ltd/synchronizer-nbp) by total FontGeek DTF, Ltd. all credit regarding the font to them.
8085

81-
Thanks to Hotel from the PROS team, Salmon from Okapilib, and Theo from 7842F, for giving some advice on improving the code here
86+
Thanks to Potatehoes from 914M for beta testing, as well as Hotel from the PROS team, Salmon from Okapilib, and Theo from 7842F, for giving some advice on improving the code here

include/screen/field.hpp

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
*
4747
* CUBE_HIGHEST represents the highest cube in the stack, followed by CUBE_2HIGHEST (the 2nd
4848
* highest), followed by CUBE_2LOWEST (the 2nd lowest), and finally CUBE_LOWEST As the 4 cube stacks
49-
* on the left and right are in the same order but slightly different positions, the corresponding
50-
* cubes are represented the same (purple to purple, orange to orange, green to green)
49+
* on the left and right are in the same order but slightly different positions
5150
*
5251
* CUBE_FAR and CUBE_NEAR are for the cube Groups farLeft and farRight
5352
*
@@ -69,14 +68,30 @@ namespace screen {
6968

7069
class Field {
7170
public:
71+
/**
72+
* A struct that controls the drawing of numbers on cubes (which represent height)
73+
*
74+
* deltaX how far to move the number horizontally from default
75+
* deltaY how far to move the number vertically from default
76+
* fontStyle which style to use; can be used to change the font, color, etc. of the number
77+
*/
78+
struct NumberConfig {
79+
int deltaX, deltaY;
80+
lv_style_t *fontStyle;
81+
};
82+
7283
/**
7384
* Field generator for the screen
7485
*
7586
* @param parent LVGL object to place upon
76-
* @param x x-value from 0-240 of the leftmost side of the field, default is centered
87+
* @param ilength the side length of the field (in both directions)
7788
* @param iautoInit print colored tiles / taped lines immediately, and after each clean
89+
* @param iconfig a configuration for the numbers on the cubes,
90+
* use deltaX and deltaY to adjust the position of the number, and set a different
91+
* style using fontStyle
7892
*/
79-
Field(lv_obj_t *parent, uint8_t x = 120, bool iautoInit = true);
93+
Field(lv_obj_t *parent, double ilength = 240, bool iautoInit = true,
94+
NumberConfig iconfig = {1, -1, &littleWhiteText});
8095
~Field();
8196

8297
/**
@@ -85,12 +100,42 @@ class Field {
85100
void clean();
86101

87102
/**
88-
* Set new x position on the screen
89-
* note: Y cannot be changed, as the field takes up the entire screen vertically
103+
* Set new x position of the field on the screen
104+
*
105+
* @param x new x-value of the distance from the leftmost side of the screen
106+
* (screen is 480 pixels wide)
107+
*/
108+
void setX(int x);
109+
110+
/**
111+
* Set new y position of the field on the screen
112+
*
113+
* @param y new y-value of the distance from the top side of the field
114+
* (screen is 240 pixels tall)
115+
*/
116+
void setY(int y);
117+
118+
/**
119+
* Set new position of the field on the screen
120+
*
121+
* note: the default(if this is never called) is 120,0 (centered)
122+
*
123+
* @param x new x-value of the distance from the leftmost side of the screen
124+
* (screen is 480 pixels wide)
125+
* @param y new y-value of the distance from the top side of the field
126+
* (screen is 240 pixels tall)
127+
*/
128+
void setPos(int x, int y);
129+
130+
/**
131+
* Set the new width and height of the field
132+
*
133+
* this will clean the screen and remove all existing objects
90134
*
91-
* @param x new x-value from 0-240 of the leftmost side of the field
135+
* note: you can make the field larger than the screen,
136+
* but you would then need a way to move the screen around in order to see it
92137
*/
93-
void setX(uint8_t x);
138+
void setSideLength(uint ilength);
94139

95140
/**
96141
* draw a group of cubes
@@ -130,14 +175,14 @@ class Field {
130175
* for both stacks. See the README for more information
131176
*/
132177
void draw(scoringZone pos, std::pair<color, color> contents,
133-
std::pair<uint8_t, uint8_t> stackHeight);
178+
std::pair<uint8_t, uint8_t> stackHeight);
134179

135180
/**
136181
* draw the four colored tiles
137182
*
138183
* called automatically by default
139184
*/
140-
void drawcoloredTiles();
185+
void drawColoredTiles();
141186

142187
/**
143188
* draw the zone lines
@@ -162,7 +207,7 @@ class Field {
162207
*
163208
* @param red true for red, false for blue
164209
* @param pos y-value of the midpoint of the robot
165-
* note: there are 40 pixels for each field tile
210+
* note: every 40 given to pos represents 1 field tile
166211
*/
167212
void drawRobot(bool red, uint8_t pos);
168213

@@ -179,8 +224,10 @@ class Field {
179224
// Cubes should be drawn automatically by the above functions
180225
void drawCube(std::pair<uint8_t, uint8_t> pos, color color, uint8_t stackHeight, bool targeted);
181226

182-
static void drawCube(lv_obj_t *parent, std::pair<uint8_t, uint8_t> pos, color color,
183-
uint8_t stackHeight, bool targeted);
227+
static void drawCube(lv_obj_t *parent, std::pair<uint8_t, uint8_t> pos, double scalar,
228+
color color, uint8_t stackHeight, NumberConfig config, bool targeted);
229+
230+
int scale(int original);
184231

185232
void resetVectors();
186233

@@ -189,13 +236,16 @@ class Field {
189236
lv_obj_t *obj;
190237

191238
bool autoInit;
239+
double scalar;
192240

193241
bool wallDrawn;
194242
std::pair<color, color> allianceTowerContents;
195243

196244
std::vector<cubeGroup> cubesToDraw;
197245
std::vector<tower> towersToDraw;
198246
std::vector<scoringZone> zonesToDraw;
247+
248+
NumberConfig config;
199249
};
200250

201251
} // namespace screen

src/opcontrol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ void opcontrol()
1313

1414
// two stacks use an array of colors
1515
// draw a purple stack with height 1 and an orange stack with height 3 in the far red zone
16-
field.draw(screen::scoringZone::farRed, {screen::color::purple, screen::color::orange},
17-
{1, 3});
16+
field.draw(screen::scoringZone::farRed, {screen::color::purple, screen::color::orange}, {1, 3});
1817

1918
// one stack does not need to use an array
2019
// draw a green stack with height 4 in the near red zone
@@ -37,7 +36,8 @@ void opcontrol()
3736
// (this is the 5 cube stack on the audience side)
3837
field.draw(screen::cubeGroup::near, CUBE_NEAR_LEFT + CUBE_NEAR_RIGHT + CUBE_FAR_RIGHT);
3938

40-
// draw the highest(rightmost), and the 2nd lowest(leftmost) cube of the 4th(closest) left cube group
39+
// draw the highest(rightmost), and the 2nd lowest(leftmost) cube of the 4th(closest) left cube
40+
// group
4141
field.draw(screen::cubeGroup::left4, CUBE_HIGHEST + CUBE_2LOWEST);
4242

4343
// draw the left tower with no cubes in or around

0 commit comments

Comments
 (0)