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

Commit 9d811f2

Browse files
author
Joseph Spencer
committed
Ready for pr
1 parent dec35dd commit 9d811f2

File tree

5 files changed

+63
-40
lines changed

5 files changed

+63
-40
lines changed

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 25 additions & 7 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,31 @@ namespace screen {
6968

7069
class Field {
7170
public:
71+
72+
/**
73+
* A struct that controls the drawing of numbers on cubes (which represent height)
74+
*
75+
* deltaX how far to move the number horizontally from default
76+
* deltaY how far to move the number vertically from default
77+
* fontStyle which style to use; can be used to change the font, color, etc. of the number
78+
*/
79+
struct NumberConfig{
80+
int deltaX, deltaY;
81+
lv_style_t* fontStyle;
82+
};
83+
7284
/**
7385
* Field generator for the screen
7486
*
7587
* @param parent LVGL object to place upon
7688
* @param ilength the side length of the field (in both directions)
7789
* @param iautoInit print colored tiles / taped lines immediately, and after each clean
90+
* @param iconfig a configuration for the numbers on the cubes,
91+
* use deltaX and deltaY to adjust the position of the number, and set a different
92+
* style using fontStyle
7893
*/
79-
Field(lv_obj_t *parent, double ilength = 240, bool iautoInit = true);
94+
Field(lv_obj_t *parent, double ilength = 240, bool iautoInit = true,
95+
NumberConfig iconfig = {1, -1, &littleWhiteText});
8096
~Field();
8197

8298
/**
@@ -90,15 +106,15 @@ class Field {
90106
* @param x new x-value of the distance from the leftmost side of the screen
91107
* (screen is 480 pixels wide)
92108
*/
93-
void setX(uint8_t x);
109+
void setX(int x);
94110

95111
/**
96112
* Set new y position of the field on the screen
97113
*
98114
* @param y new y-value of the distance from the top side of the field
99115
* (screen is 240 pixels tall)
100116
*/
101-
void setY(uint8_t y);
117+
void setY(int y);
102118

103119
/**
104120
* Set new position of the field on the screen
@@ -110,7 +126,7 @@ class Field {
110126
* @param y new y-value of the distance from the top side of the field
111127
* (screen is 240 pixels tall)
112128
*/
113-
void setPos(uint8_t x, uint8_t y);
129+
void setPos(int x, int y);
114130

115131
/**
116132
* Set the new width and height of the field
@@ -210,7 +226,7 @@ class Field {
210226
void drawCube(std::pair<uint8_t, uint8_t> pos, color color, uint8_t stackHeight, bool targeted);
211227

212228
static void drawCube(lv_obj_t *parent, std::pair<uint8_t, uint8_t> pos, double scalar, color color,
213-
uint8_t stackHeight, bool targeted);
229+
uint8_t stackHeight, NumberConfig config, bool targeted);
214230

215231
int scale(int original);
216232

@@ -229,6 +245,8 @@ class Field {
229245
std::vector<cubeGroup> cubesToDraw;
230246
std::vector<tower> towersToDraw;
231247
std::vector<scoringZone> zonesToDraw;
248+
249+
NumberConfig config;
232250
};
233251

234252
} // namespace screen

src/opcontrol.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ void opcontrol()
1111

1212
screen::Field field(scr);
1313

14-
field.setSideLength(400);
15-
1614
// two stacks use an array of colors
1715
// draw a purple stack with height 1 and an orange stack with height 3 in the far red zone
1816
field.draw(screen::scoringZone::farRed, {screen::color::purple, screen::color::orange},

src/screen/field.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace screen {
44

5-
Field::Field(lv_obj_t *parent, const double ilength, const bool iautoInit)
6-
: scalar(ilength / 240), autoInit(iautoInit), wallDrawn(false),
7-
allianceTowerContents(color::none, color::none)
5+
Field::Field(lv_obj_t *parent, const double ilength, const bool iautoInit,
6+
const NumberConfig iconfig):
7+
scalar(ilength / 240), autoInit(iautoInit), config(iconfig),
8+
wallDrawn(false), allianceTowerContents(color::none, color::none)
89
{
910
obj = lv_obj_create(parent, NULL);
1011
lv_obj_set_style(obj, &fieldStyle);
11-
lv_obj_set_size(obj, scale(240), scale(240));
12+
lv_obj_set_size(obj, ilength, ilength);
1213
lv_obj_set_pos(obj, 120, 0);
1314

1415
resetVectors();
@@ -38,25 +39,25 @@ void Field::clean()
3839
}
3940
}
4041

41-
void Field::setX(uint8_t x)
42+
void Field::setX(int x)
4243
{
4344
lv_obj_set_x(obj, x);
4445
}
4546

46-
void Field::setY(uint8_t y)
47+
void Field::setY(int y)
4748
{
4849
lv_obj_set_y(obj, y);
4950
}
5051

51-
void Field::setPos(uint8_t x, uint8_t y)
52+
void Field::setPos(int x, int y)
5253
{
5354
lv_obj_set_pos(obj, x, y);
5455
}
5556

5657
void Field::setSideLength(uint ilength){
5758
scalar = ilength / 240.0;
58-
clean();
5959
lv_obj_set_size(obj, ilength, ilength);
60+
clean();
6061
}
6162

6263
void Field::draw(const cubeGroup pos, const uint8_t presence)
@@ -227,7 +228,7 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
227228
lv_obj_set_style(tower, &neutralTower);
228229
lv_obj_set_pos(tower, scale(32), scale(112));
229230

230-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
231+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
231232

232233
if (cubePresence & 0b11111000) {
233234
drawCube({35, 101}, color::purple, 1, targeted);
@@ -243,7 +244,7 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
243244
lv_obj_set_style(tower, &neutralTower);
244245
lv_obj_set_pos(tower, scale(192), scale(112));
245246

246-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
247+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
247248

248249
if (cubePresence & 0b11111000) {
249250
drawCube({195, 101}, color::purple, 1, targeted);
@@ -259,7 +260,7 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
259260
lv_obj_set_style(tower, &neutralTower);
260261
lv_obj_set_pos(tower, scale(112), scale(112));
261262

262-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
263+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
263264
if (cubePresence & 0b11111000) {
264265
drawCube({115, 101}, color::purple, 1, targeted);
265266
}
@@ -277,7 +278,7 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
277278
lv_obj_set_style(tower, &neutralTower);
278279
lv_obj_set_pos(tower, scale(112), scale(52));
279280

280-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
281+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
281282
if (cubePresence & 0b11111000) {
282283
drawCube({115, 41}, color::purple, 1, targeted);
283284
}
@@ -295,7 +296,7 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
295296
lv_obj_set_style(tower, &neutralTower);
296297
lv_obj_set_pos(tower, scale(112), scale(172));
297298

298-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
299+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
299300
if (cubePresence & 0b11111000) {
300301
drawCube({115, 161}, color::purple, 1, targeted);
301302
}
@@ -313,13 +314,13 @@ void Field::draw(const tower pos, const color contents, const uint8_t cubePresen
313314
lv_obj_set_style(tower, &redTower);
314315
lv_obj_set_pos(tower, scale(54), scale(228));
315316

316-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
317+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
317318
break;
318319
case tower::blue:
319320
lv_obj_set_style(tower, &blueTower);
320321
lv_obj_set_pos(tower, scale(174), scale(228));
321322

322-
drawCube(tower, {3, 3}, scalar, contents, 1, true);
323+
drawCube(tower, {3, 3}, scalar, contents, 1, config, true);
323324
break;
324325
}
325326
}
@@ -350,8 +351,8 @@ void Field::draw(const scoringZone pos, const std::pair<color, color> contents,
350351
lv_obj_set_pos(zone, 0, 0);
351352

352353
if (targeted) {
353-
drawCube(zone, {4, 5}, scalar, contents.first, stackHeight.first, false);
354-
drawCube(zone, {15, 5}, scalar, contents.second, stackHeight.second, false);
354+
drawCube(zone, {4, 5}, scalar, contents.first, stackHeight.first, config, false);
355+
drawCube(zone, {15, 5}, scalar, contents.second, stackHeight.second, config, false);
355356
}
356357
break;
357358
case scoringZone::farBlue:
@@ -360,8 +361,8 @@ void Field::draw(const scoringZone pos, const std::pair<color, color> contents,
360361
lv_obj_set_pos(zone, scale(211), 0);
361362

362363
if (targeted) {
363-
drawCube(zone, {15, 5}, scalar, contents.first, stackHeight.first, false);
364-
drawCube(zone, {4, 5}, scalar, contents.second, stackHeight.second, false);
364+
drawCube(zone, {15, 5}, scalar, contents.first, stackHeight.first, config, false);
365+
drawCube(zone, {4, 5}, scalar, contents.second, stackHeight.second, config, false);
365366
}
366367
break;
367368
case scoringZone::nearRed:
@@ -370,7 +371,7 @@ void Field::draw(const scoringZone pos, const std::pair<color, color> contents,
370371
lv_obj_set_pos(zone, 0, scale(220));
371372

372373
if (targeted) {
373-
drawCube(zone, {5, 5}, scalar, contents.first, stackHeight.first, false);
374+
drawCube(zone, {5, 5}, scalar, contents.first, stackHeight.first, config, false);
374375
}
375376
break;
376377
case scoringZone::nearBlue:
@@ -379,7 +380,7 @@ void Field::draw(const scoringZone pos, const std::pair<color, color> contents,
379380
lv_obj_set_pos(zone, scale(220), scale(220));
380381

381382
if (targeted) {
382-
drawCube(zone, {5, 5}, scalar, contents.first, stackHeight.first, false);
383+
drawCube(zone, {5, 5}, scalar, contents.first, stackHeight.first, config, false);
383384
}
384385
break;
385386
}
@@ -488,11 +489,12 @@ void Field::finishDrawing()
488489
void Field::drawCube(const std::pair<uint8_t, uint8_t> pos, const color color,
489490
const uint8_t stackHeight, const bool targeted)
490491
{
491-
drawCube(obj, pos, scalar, color, stackHeight, targeted);
492+
drawCube(obj, pos, scalar, color, stackHeight, config, targeted);
492493
}
493494

494495
void Field::drawCube(lv_obj_t *parent, const std::pair<uint8_t, uint8_t> pos, double scalar,
495-
const color color, const uint8_t stackHeight, const bool targeted)
496+
const color color, const uint8_t stackHeight, const NumberConfig config,
497+
const bool targeted)
496498
{
497499
if (color == color::none)
498500
return;
@@ -508,10 +510,10 @@ void Field::drawCube(lv_obj_t *parent, const std::pair<uint8_t, uint8_t> pos, do
508510

509511
if (stackHeight > 1) {
510512
lv_obj_t *cubeLabel = lv_label_create(cube, NULL);
511-
lv_label_set_style(cubeLabel, &littleWhiteText);
512-
lv_obj_align(cubeLabel, NULL, LV_ALIGN_CENTER, -1, -1);
513+
lv_label_set_style(cubeLabel, config.fontStyle);
514+
lv_obj_align(cubeLabel, NULL, LV_ALIGN_CENTER, config.deltaX, config.deltaY);
513515
lv_label_set_align(cubeLabel, LV_LABEL_ALIGN_CENTER);
514-
lv_label_set_text(cubeLabel, (" " + std::to_string(stackHeight)).c_str());
516+
lv_label_set_text(cubeLabel, std::to_string(stackHeight).c_str());
515517
}
516518
}
517519

0 commit comments

Comments
 (0)