Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add portrait support for move axis screen for TS35 #25945

Merged
merged 9 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 209 additions & 82 deletions Marlin/src/lcd/tft/ui_480x320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,17 @@ static void quick_feedback() {
#define CUR_STEP_VALUE_WIDTH 104
static void drawCurStepValue() {
tft_string.set(ftostr52sp(motionAxisState.currentStepSize));
tft_string.trim();
tft_string.add(F("mm"));
tft.canvas(motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(tft_string.center(CUR_STEP_VALUE_WIDTH), 0, COLOR_AXIS_HOMED, tft_string);
tft.add_text(0, 0, COLOR_AXIS_HOMED, tft_string);
}

#if HAS_Z_AXIS
static void drawCurZSelection() {
tft_string.set('Z');
tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), 34);
tft.canvas(motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, tft_string.width(), FONT_LINE_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, Z_BTN_COLOR, tft_string);

Expand All @@ -669,13 +670,17 @@ static void drawCurStepValue() {
tft.canvas(motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT);
tft.set_background(COLOR_BACKGROUND);
tft_string.set('E');
tft.add_text(0, 0, E_BTN_COLOR , tft_string);
tft.add_text(tft_string.width(), 0, E_BTN_COLOR, ui8tostr3rj(motionAxisState.e_selection));
tft_string.add(utostr3(motionAxisState.e_selection));
tft.add_text(tft_string.center(BTN_WIDTH), 0, E_BTN_COLOR, tft_string);
}
#endif

static void drawMessage(PGM_P const msg) {
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - Y_OFFSET, TFT_HEIGHT / 2, Y_OFFSET);
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
tft.canvas(X_MARGIN, TFT_HEIGHT - 2 * MOVE_AXIS_MARGIN_SIZE - BTN_HEIGHT - FONT_LINE_HEIGHT, TFT_WIDTH - X_MARGIN * 2, FONT_LINE_HEIGHT);
#else
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - Y_OFFSET, TFT_HEIGHT / 2, Y_OFFSET);
#endif
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, COLOR_YELLOW, msg);
}
Expand Down Expand Up @@ -707,7 +712,8 @@ static void drawAxisValue(const AxisEnum axis) {
tft.canvas(pos.x, pos.y, BTN_WIDTH + X_MARGIN, BTN_HEIGHT TERN_(HAS_UI_480x272, / 2));
tft.set_background(COLOR_BACKGROUND);
tft_string.set(ftostr52sp(value));
tft.add_text(0, 0, color, tft_string);
tft_string.trim();
tft.add_text(tft_string.center(BTN_WIDTH + X_MARGIN), 0, color, tft_string);
}

static void moveAxis(const AxisEnum axis, const int8_t direction) {
Expand Down Expand Up @@ -898,108 +904,229 @@ void MarlinUI::move_axis_screen() {
if (busy) motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
#endif

// ROW 1 -> E+ Y+ CurY Z+
int x = X_MARGIN, y = Y_MARGIN, spacing = 0;
#if ENABLED(TFT_COLOR_UI_PORTRAIT)

TERN_(HAS_EXTRUDERS, drawBtn(x, y, "E+", (intptr_t)e_plus, imgUp, E_BTN_COLOR, !busy));
int y = MOVE_AXIS_MARGIN_SIZE;

spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;
x += BTN_WIDTH + spacing;
/**************************************************************************
* 1st: | Button "E+" | Button "Y+" | Button "Z+" |
*************************************************************************/

TERN_(HAS_Y_AXIS, drawBtn(x, y, "Y+", (intptr_t)y_plus, imgUp, Y_BTN_COLOR, !busy));
TERN_(HAS_EXTRUDERS, drawBtn(TFT_WIDTH / 6 - BTN_WIDTH / 2, y, "E+", (intptr_t)e_plus, imgUp, E_BTN_COLOR, !busy));
TERN_(HAS_Y_AXIS, drawBtn(TFT_WIDTH / 2 - BTN_WIDTH / 2, y, "Y+", (intptr_t)y_plus, imgUp, Y_BTN_COLOR, !busy));
TERN_(HAS_Z_AXIS, drawBtn(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y, "Z+", (intptr_t)z_plus, imgUp, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)));

x += BTN_WIDTH;
y += BTN_HEIGHT + 4;

// Cur Y
#if HAS_Y_AXIS
motionAxisState.yValuePos.set(x + 2, y);
drawAxisValue(Y_AXIS);
#endif
/**************************************************************************
* 2nd: | Label "Ex" (E0, E1, etc.) | Y value | Label "Z" |
*************************************************************************/

x += spacing;
#if HAS_Z_AXIS
drawBtn(x, y, "Z+", (intptr_t)z_plus, imgUp, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
#endif
// Label "Ex" (E0, E1, etc.)
#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(TFT_WIDTH / 6 - BTN_WIDTH / 2, y);
drawCurESelection();
#if ENABLED(TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, motionAxisState.eNamePos.x, motionAxisState.eNamePos.y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select);
#endif
#endif

// ROW 2 -> "Ex" X- HOME X+ "Z"
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4;
// Y value
#if HAS_Y_AXIS
motionAxisState.yValuePos.set(TFT_WIDTH / 2 - (BTN_WIDTH + X_MARGIN) / 2, y);
drawAxisValue(Y_AXIS);
#endif

#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(x, y);
drawCurESelection();
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
#endif
// Label "Z"
#ifdef HAS_Z_AXIS
motionAxisState.zTypePos.set(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y);
drawCurZSelection();
#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, motionAxisState.zTypePos.x, motionAxisState.zTypePos.y, BTN_WIDTH, FONT_LINE_HEIGHT * 2, (intptr_t)z_select);
#endif
#endif

x += BTN_WIDTH + spacing;
y += BTN_HEIGHT + MOVE_AXIS_MARGIN_SIZE;

TERN_(HAS_X_AXIS, drawBtn(x, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy));
/**************************************************************************
* 3rd: | Button "X-" | Button "Homing" | Button "X+" |
*************************************************************************/

x += BTN_WIDTH + spacing; //imgHome is 64x64
#if HAS_X_AXIS
drawBtn(TFT_WIDTH / 6 - BTN_WIDTH / 2, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy);
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
drawBtn(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y, "X+", (intptr_t)x_plus, imgRight, X_BTN_COLOR, !busy);
#endif

#if ALL(HAS_X_AXIS, TOUCH_SCREEN)
add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy);
#endif
y += BTN_HEIGHT + 4;

x += BTN_WIDTH + spacing;
uint16_t xplus_x = x;
/**************************************************************************
* 4th: | X value |
*************************************************************************/

TERN_(HAS_X_AXIS, drawBtn(x, y, "X+", (intptr_t)x_plus, imgRight, X_BTN_COLOR, !busy));
#ifdef HAS_X_AXIS
motionAxisState.xValuePos.set(TFT_WIDTH / 6 - (BTN_WIDTH + X_MARGIN) / 2, y);
drawAxisValue(X_AXIS);
#endif

x += BTN_WIDTH + spacing;
y += BTN_HEIGHT + MOVE_AXIS_MARGIN_SIZE;

#if HAS_Z_AXIS
motionAxisState.zTypePos.set(x, y);
drawCurZSelection();
#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, Y_OFFSET * 2, (intptr_t)z_select);
/**************************************************************************
* 5th: | Button "E-" | Button "Y-" | Button "Z-"
*************************************************************************/

TERN_(HAS_EXTRUDERS, drawBtn(TFT_WIDTH / 6 - BTN_WIDTH / 2, y, "E-", (intptr_t)e_minus, imgDown, E_BTN_COLOR, !busy));
TERN_(HAS_Y_AXIS, drawBtn(TFT_WIDTH / 2 - BTN_WIDTH / 2, y, "Y-", (intptr_t)y_minus, imgDown, Y_BTN_COLOR, !busy));
TERN_(HAS_Z_AXIS, drawBtn(TFT_WIDTH * 5 / 6 - BTN_WIDTH / 2, y, "Z-", (intptr_t)z_minus, imgDown, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)));

y += BTN_HEIGHT + 4;

/**************************************************************************
* 6th: | Current Ex value | Z value |
*************************************************************************/

// Current Ex value
#ifdef HAS_EXTRUDERS
motionAxisState.eValuePos.set(TFT_WIDTH / 6 - (BTN_WIDTH + X_MARGIN) / 2, y);
drawAxisValue(E_AXIS);
#endif
#endif

// ROW 3 -> E- CurX Y- Z-
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;
#ifdef HAS_Z_AXIS
motionAxisState.zValuePos.set(TFT_WIDTH * 5 / 6 - (BTN_WIDTH + X_MARGIN) / 2, y);
drawAxisValue(Z_AXIS);
#endif

#if HAS_EXTRUDERS
drawBtn(x, y, "E-", (intptr_t)e_minus, imgDown, E_BTN_COLOR, !busy);
motionAxisState.eValuePos.set(x, y + BTN_HEIGHT + 2);
drawAxisValue(E_AXIS);
#endif
y += BTN_HEIGHT + MOVE_AXIS_MARGIN_SIZE;

#if HAS_X_AXIS
motionAxisState.xValuePos.set(BTN_WIDTH + (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4, y - 10);
TERN_(HAS_X_AXIS, drawAxisValue(X_AXIS));
#endif
/**************************************************************************
* 7th: | Message - drawMessage(...) function |
*************************************************************************/

x += BTN_WIDTH + spacing;
TERN_(HAS_Y_AXIS, drawBtn(x, y, "Y-", (intptr_t)y_minus, imgDown, Y_BTN_COLOR, !busy));
y += FONT_LINE_HEIGHT + MOVE_AXIS_MARGIN_SIZE;

x += BTN_WIDTH + spacing;
#if HAS_Z_AXIS
drawBtn(x, y, "Z-", (intptr_t)z_minus, imgDown, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
#endif
/**************************************************************************
* 8th: | Step size | Button "Disable steppers" | Button "Back" |
*************************************************************************/

// Cur Z
#if HAS_Z_AXIS
motionAxisState.zValuePos.set(x, y + BTN_HEIGHT + 2);
drawAxisValue(Z_AXIS);
#endif
// Step size
motionAxisState.stepValuePos.set(X_MARGIN, y + 12);
if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y + 12, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
}

// ROW 4 -> step_size disable steppers back
y = TFT_HEIGHT - Y_MARGIN - TERN(HAS_UI_480x272, BTN_WIDTH / 2, 32);
x = TFT_WIDTH / 2 - CUR_STEP_VALUE_WIDTH / 2;
motionAxisState.stepValuePos.set(x, y);
if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
}
// Button "Disable steppers"
drawBtn(TFT_WIDTH / 2, y, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);

// Button "Back"
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH * 5 / 6 - Images[imgBack].width / 2, y + 12, BACK, imgBack));

#else // !TFT_COLOR_UI_PORTRAIT

// ROW 1 -> E- Y- CurY Z+
int x = X_MARGIN, y = Y_MARGIN, spacing = 0;

TERN_(HAS_EXTRUDERS, drawBtn(x, y, "E+", (intptr_t)e_plus, imgUp, E_BTN_COLOR, !busy));

spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;
x += BTN_WIDTH + spacing;

TERN_(HAS_Y_AXIS, drawBtn(x, y, "Y+", (intptr_t)y_plus, imgUp, Y_BTN_COLOR, !busy));

x += BTN_WIDTH;

// Cur Y
#if HAS_Y_AXIS
motionAxisState.yValuePos.set(x + 2, y);
drawAxisValue(Y_AXIS);
#endif

x += spacing;
#if HAS_Z_AXIS
drawBtn(x, y, "Z+", (intptr_t)z_plus, imgUp, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
#endif

// ROW 2 -> "Ex" X- HOME X+ "Z"
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4;

#if HAS_EXTRUDERS
motionAxisState.eNamePos.set(x, y);
drawCurESelection();
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
#endif

x += BTN_WIDTH + spacing;

TERN_(HAS_X_AXIS, drawBtn(x, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy));

x += BTN_WIDTH + spacing; //imgHome is 64x64

#if ALL(HAS_X_AXIS, TOUCH_SCREEN)
add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy);
#endif

x += BTN_WIDTH + spacing;
uint16_t xplus_x = x;

TERN_(HAS_X_AXIS, drawBtn(x, y, "X+", (intptr_t)x_plus, imgRight, X_BTN_COLOR, !busy));

x += BTN_WIDTH + spacing;

#if HAS_Z_AXIS
motionAxisState.zTypePos.set(x, y);
drawCurZSelection();
#if ALL(HAS_BED_PROBE, TOUCH_SCREEN)
if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, Y_OFFSET * 2, (intptr_t)z_select);
#endif
#endif

// ROW 3 -> E- CurX Y- Z-
y += BTN_HEIGHT + (TFT_HEIGHT - Y_MARGIN * 2 - 4 * BTN_HEIGHT) / 3;
x = X_MARGIN;
spacing = (TFT_WIDTH - X_MARGIN * 2 - 3 * BTN_WIDTH) / 2;

#if HAS_EXTRUDERS
drawBtn(x, y, "E-", (intptr_t)e_minus, imgDown, E_BTN_COLOR, !busy);
motionAxisState.eValuePos.set(x, y + BTN_HEIGHT + 2);
drawAxisValue(E_AXIS);
#endif

#if HAS_X_AXIS
motionAxisState.xValuePos.set(BTN_WIDTH + (TFT_WIDTH - X_MARGIN * 2 - 5 * BTN_WIDTH) / 4, y - 10);
TERN_(HAS_X_AXIS, drawAxisValue(X_AXIS));
#endif

x += BTN_WIDTH + spacing;
TERN_(HAS_Y_AXIS, drawBtn(x, y, "Y-", (intptr_t)y_minus, imgDown, Y_BTN_COLOR, !busy));

x += BTN_WIDTH + spacing;
#if HAS_Z_AXIS
drawBtn(x, y, "Z-", (intptr_t)z_minus, imgDown, Z_BTN_COLOR, !busy || ENABLED(BABYSTEP_ZPROBE_OFFSET)); //only enabled when not busy or have baby step
#endif

// Cur Z
#if HAS_Z_AXIS
motionAxisState.zValuePos.set(x, y + BTN_HEIGHT + 2);
drawAxisValue(Z_AXIS);
#endif

// ROW 4 -> step_size disable steppers back
y = TFT_HEIGHT - Y_MARGIN - TERN(HAS_UI_480x272, BTN_WIDTH / 2, 32);
x = TFT_WIDTH / 2 - CUR_STEP_VALUE_WIDTH / 2;
motionAxisState.stepValuePos.set(x, y);
if (!busy) {
drawCurStepValue();
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
}

// aligned with x+
drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);

// aligned with x+
drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));

TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
#endif // !TFT_COLOR_UI_PORTRAIT
}

#endif // HAS_UI_480x320 || HAS_UI_480x272
4 changes: 4 additions & 0 deletions Marlin/src/lcd/tft/ui_480x320.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
#if ENABLED(TOUCH_SCREEN)
#define STATUS_TOTAL_ROWS_HEIGHT (2 * FONT_LINE_HEIGHT + 120 + 32 + 64 + 29 + 7)
#define STATUS_MARGINS_REGIONS 8

#define MOVE_AXIS_TOTAL_ROWS_HEIGHT (7 * BTN_HEIGHT + FONT_LINE_HEIGHT + 12)
#define MOVE_AXIS_MARGIN_REGIONS 6
#define MOVE_AXIS_MARGIN_SIZE ((TFT_HEIGHT - MOVE_AXIS_TOTAL_ROWS_HEIGHT) / MOVE_AXIS_MARGIN_REGIONS)
#else
#define STATUS_TOTAL_ROWS_HEIGHT (2 * FONT_LINE_HEIGHT + 120 + 32 + 29 + 7)
#define STATUS_MARGINS_REGIONS 7
Expand Down