Enum in a void function
in
Programming Questions
•
1 year ago
I'm working on a function to Align a rectangle in X Y, for example RC = right center, LB = LEFT BOTTOM.
For this i want to use enum instand of checking for string equal, i only get this error:
Cannot switch on a value of type Enum. Only convertible int values or enum constants are permitted
Does someone know a fix?
This is in Align.java
- enum Align {
- /*
- * LT ---- CT ---- RT
- * | | |
- * | | |
- * LC ---- CC ---- RC
- * | | |
- * | | |
- * LB ---- CB ---- RB
- */
- LT,
- CT,
- RT,
- LC,
- CC,
- RC,
- LB,
- CB,
- RB
- }
- void setup() {
- size(600, 600);
- }
- void draw() {
- background(255);
- noStroke();
- fill(255, 0, 0, 50);
- rect(width/2, height/2, 100, 100, 1, 1);
- rect(width/2, height/2, 100, 100, 0.5, 0.5);
- rect(width/2, height/2, 100, 100, 1, 0);
- rect(0, 0, 100, 100, Align.CC);
- }
- void rect(float x, float y, float w, float h, Enum Align) {
- /*
- * LT ---- CT ---- RT
- * | | |
- * | | |
- * LC ---- CC ---- RC
- * | | |
- * | | |
- * LB ---- CB ---- RB
- */
- switch(Align) {
- case LT:
- rect(x, y, w, h, 0, 0);
- break;
- case CT:
- rect(x, y, w, h, 0.5, 0);
- break;
- case RT:
- rect(x, y, w, h, 1, 0);
- break;
- case LC:
- rect(x, y, w, h, 0, 0.5);
- break;
- case CC:
- rect(x, y, w, h, 0.5, 0.5);
- break;
- case RC:
- rect(x, y, w, h, 1, 0.5);
- break;
- case LB:
- rect(x, y, w, h, 0, 1);
- break;
- case CB:
- rect(x, y, w, h, 0.5, 1);
- break;
- case RB:
- rect(x, y, w, h, 1, 1);
- break;
- }
- }
- void rect(float x, float y, float w, float h, float alignX, float alignY) {
- /*
- * 0 0 -------- 1 0
- * | |
- * | |
- * | |
- * | |
- * | |
- * 0 1 -------- 1 1
- */
- pushStyle();
- rectMode(CORNER);
- float xShift = x - w*alignX;
- float yShift = y - h*alignY;
- rect(xShift, yShift, w, h);
- popStyle();
- }
1