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

Commit

Permalink
Merge pull request #4 from SpencerJ21/scaling
Browse files Browse the repository at this point in the history
Scaling
  • Loading branch information
jm-spencer committed Jun 9, 2019
2 parents ab97496 + b6189ca commit 8942922
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ bin/

compile_commands.json
temp.log

*.zip
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ USE_PACKAGE:=0
IS_LIBRARY:=1
# TODO: CHANGE THIS!
LIBNAME:=screenlib
VERSION:=1.0.0
VERSION:=1.0.1
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/opcontrol $(SRCDIR)/initialize $(SRCDIR)/autonomous,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))

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

.DEFAULT_GOAL=quick

Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Version
=======
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
The second digit refers to any new features that may be added.
The third digit refers to any bug fixes.
The third digit refers to any bug fixes or minor improvements to existing features.

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

`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`
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)

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

`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

and finally, all macros starting with `TOWER_CUBE_` refer to the cubes around a tower
and finally, all macros starting with `TOWER_CUBE_` refer to the cubes around a tower

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

Other
-----
The field can be repositioned with `setX`, `setY`, or `setPos`.
and can be resized using `setSideLength`
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)

Example
-------
This directory (specifically [opcontrol.cpp](./src/opcontrol.cpp)) is a usage example (it produces the image at the top of this page)
Expand All @@ -78,4 +83,4 @@ Acknowledgements
================
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.

Thanks to Hotel from the PROS team, Salmon from Okapilib, and Theo from 7842F, for giving some advice on improving the code here
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
76 changes: 63 additions & 13 deletions include/screen/field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
*
* 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 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)
* on the left and right are in the same order but slightly different positions
*
* CUBE_FAR and CUBE_NEAR are for the cube Groups farLeft and farRight
*
Expand All @@ -69,14 +68,30 @@ namespace screen {

class Field {
public:
/**
* A struct that controls the drawing of numbers on cubes (which represent height)
*
* deltaX how far to move the number horizontally from default
* deltaY how far to move the number vertically from default
* fontStyle which style to use; can be used to change the font, color, etc. of the number
*/
struct NumberConfig {
int deltaX, deltaY;
lv_style_t *fontStyle;
};

/**
* Field generator for the screen
*
* @param parent LVGL object to place upon
* @param x x-value from 0-240 of the leftmost side of the field, default is centered
* @param ilength the side length of the field (in both directions)
* @param iautoInit print colored tiles / taped lines immediately, and after each clean
* @param iconfig a configuration for the numbers on the cubes,
* use deltaX and deltaY to adjust the position of the number, and set a different
* style using fontStyle
*/
Field(lv_obj_t *parent, uint8_t x = 120, bool iautoInit = true);
Field(lv_obj_t *parent, double ilength = 240, bool iautoInit = true,
NumberConfig iconfig = {1, -1, &littleWhiteText});
~Field();

/**
Expand All @@ -85,12 +100,42 @@ class Field {
void clean();

/**
* Set new x position on the screen
* note: Y cannot be changed, as the field takes up the entire screen vertically
* Set new x position of the field on the screen
*
* @param x new x-value of the distance from the leftmost side of the screen
* (screen is 480 pixels wide)
*/
void setX(int x);

/**
* Set new y position of the field on the screen
*
* @param y new y-value of the distance from the top side of the field
* (screen is 240 pixels tall)
*/
void setY(int y);

/**
* Set new position of the field on the screen
*
* note: the default(if this is never called) is 120,0 (centered)
*
* @param x new x-value of the distance from the leftmost side of the screen
* (screen is 480 pixels wide)
* @param y new y-value of the distance from the top side of the field
* (screen is 240 pixels tall)
*/
void setPos(int x, int y);

/**
* Set the new width and height of the field
*
* this will clean the screen and remove all existing objects
*
* @param x new x-value from 0-240 of the leftmost side of the field
* note: you can make the field larger than the screen,
* but you would then need a way to move the screen around in order to see it
*/
void setX(uint8_t x);
void setSideLength(uint ilength);

/**
* draw a group of cubes
Expand Down Expand Up @@ -130,14 +175,14 @@ class Field {
* for both stacks. See the README for more information
*/
void draw(scoringZone pos, std::pair<color, color> contents,
std::pair<uint8_t, uint8_t> stackHeight);
std::pair<uint8_t, uint8_t> stackHeight);

/**
* draw the four colored tiles
*
* called automatically by default
*/
void drawcoloredTiles();
void drawColoredTiles();

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

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

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

int scale(int original);

void resetVectors();

Expand All @@ -189,13 +236,16 @@ class Field {
lv_obj_t *obj;

bool autoInit;
double scalar;

bool wallDrawn;
std::pair<color, color> allianceTowerContents;

std::vector<cubeGroup> cubesToDraw;
std::vector<tower> towersToDraw;
std::vector<scoringZone> zonesToDraw;

NumberConfig config;
};

} // namespace screen
Expand Down
6 changes: 3 additions & 3 deletions src/opcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ void opcontrol()

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

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

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

// draw the left tower with no cubes in or around
Expand Down
Loading

0 comments on commit 8942922

Please sign in to comment.