Skip to content

Commit

Permalink
reescalado de texto e imagenes (mas o menos,)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonandra committed Nov 5, 2022
1 parent a257721 commit 8d5c401
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 19 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public AEngine(Context context, AssetManager assetManager) {
this.stateManager = new StateManager(this, 0.5f);
this.inputManager = new AInput();
this.assetManager = assetManager;


}

public Canvas getCurrentCanvas(){
Expand Down Expand Up @@ -169,6 +171,11 @@ public String getAssetsPath() {
return "";
}

@Override
public boolean supportsTouch() {
return true;
}

public void render() {
// "Borramos" el fondo.
//graphics.clear(255,255,255);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setColor(int r, int g, int b, int a) {
//HABRIA QUE HACER LA CONERSION de rgb a HEXADECIMAL
/*Canvas canvas = engine.getCurrentCanvas();
canvas.drawARGB(a,r,g,b); // ARGB*/
paint.setColor( Color.rgb(r, g, b) );
paint.setColor( Color.argb(a,r,g,b) );
}

@Override
Expand Down Expand Up @@ -147,23 +147,37 @@ public void drawImage(IImage image, int x, int y) {
//current canvas displayed
Canvas canvas = engine.getCurrentCanvas();
// Paint paint = new Paint(); //paint ya se creo en AndroidEngine & lo recibes en la constructora

int uLx = logicXPositionToWindowsXPosition(x - x/2); int uLy = logicYPositionToWindowsYPosition(y - y/2);
int dRx = (int)(((AImage)image).getWidth() * scaleX * scaleFactor) + uLx;
int dRy = (int)(((AImage)image).getHeight() * scaleY * scaleFactor) + uLy;
Rect r = new Rect(uLx,uLy, dRx,dRy);
//draw //recibe un bitmap
canvas.drawBitmap(((AImage)image).getBitmap(), x, y, paint);
canvas.drawBitmap(((AImage)image).getBitmap(), null,r,paint);
//canvas.drawBitmap(((AImage)image).getBitmap(), x, y, paint);

}

@Override
public void drawRectangle(int upperLeftX, int upperLeftY, int lowerRightX, int lowerRightY, int lineWidth) {
public void drawRectangle(int x, int y, int width, int height,int lineWidth ) {
//SURFACE VIEW IS CORRECTLY INITIALIZED

int upperLeftX, upperLeftY, lowerRightX, lowerRightY;
upperLeftX = x - (width / 2);
upperLeftY = y - (height / 2);
lowerRightX = x + (width / 2);
lowerRightY = y + (height / 2);

int uLx = logicXPositionToWindowsXPosition(upperLeftX);
int uLy = logicYPositionToWindowsYPosition(upperLeftY);
int lRx = logicXPositionToWindowsXPosition(lowerRightX);
int lRy = logicYPositionToWindowsYPosition(lowerRightY);
//current canvas displayed
Canvas canvas = engine.getCurrentCanvas();
//PINTAR EL FONDO EN BLANCO-----------------
paint.setStyle(Paint.Style.STROKE); //????????????????????????????????????????????????

paint.setStrokeWidth(lineWidth);
//draw
canvas.drawRect(upperLeftX, upperLeftY, lowerRightX, lowerRightY, paint);
canvas.drawRect(uLx, uLy, lRx, lRy, paint);
paint.reset();
}

Expand Down Expand Up @@ -254,7 +268,7 @@ public void drawText(String text, int x, int y, IFont font) {
Canvas canvas = engine.getCurrentCanvas();
//esto no va
//paint.setTypeface(((AFont)font).getFont());
paint.setTextSize(((AFont)font).getSize());
paint.setTextSize((float)(((AFont)font).getSize() * scaleFactor));
canvas.drawText(text, x, y, paint);
paint.reset();
}
Expand All @@ -268,12 +282,12 @@ public void drawTextCentered(String text, int x, int y, IFont font) {
/* int processedX = logicXPositionToWindowsXPosition(x);
int processedY = logicYPositionToWindowsYPosition(y);*/

paint.setTextSize(((AFont)font).getSize());
paint.setTextSize((float)(((AFont)font).getSize() * scaleFactor * scaleX));

int halfSwidth = (int)(((int)(getStringWidth(text, font) * scaleX) /scaleFactor)/ 2);
//int haldSheight = (int)(((int)(getFontHeight(font) * scaleY) / scaleFactor) / 2);
int halfSwidth = (int)(((int)(getStringWidth(text, font)) /scaleFactor)/ 2);
int halfSheight = (int)(((int)(getFontHeight(font) ) / scaleFactor) / 2);
int processedX = logicXPositionToWindowsXPosition(x- halfSwidth);
int processedY = logicYPositionToWindowsYPosition(y );
int processedY = logicYPositionToWindowsYPosition(y + halfSheight );


canvas.drawText(text, processedX, processedY, paint);
Expand All @@ -295,6 +309,7 @@ public int getLogicWidth() {
return this.logicSizeX;
}


@Override
public int getLogicHeight() {
return this.logicSizeY;
Expand All @@ -303,7 +318,9 @@ public int getLogicHeight() {
//hay transiciones pero no van con int
@Override
public void setGraphicsAlpha(int alpha) {
engine.getCurrentView().setAlpha(alpha);
/* float value = alpha / 255;
engine.setAlpha(value);*/
paint.setAlpha(alpha);
}

@Override
Expand All @@ -323,12 +340,14 @@ public void rotate(double angleDegrees) {

@Override
public int logicXPositionToWindowsXPosition(int x) {
return (int) (((x + (int) (borderBarWidth / scaleFactor) ) / scaleX) * scaleFactor);
return (int) (((x + (int) (borderBarWidth / scaleFactor) ) ) * scaleFactor);
//return (int) (((x + (int) (borderBarWidth / scaleFactor) ) / scaleX) * scaleFactor);
}

@Override
public int logicYPositionToWindowsYPosition(int y) {
return (int) (((y + (int) (topBarHeight / scaleFactor) ) / scaleY)* scaleFactor);
return (int) (((y + (int) (topBarHeight / scaleFactor) ))* scaleFactor);
//return (int) (((y + (int) (topBarHeight / scaleFactor) ) / scaleY)* scaleFactor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public AImage(String pathToImage, AssetManager assetManager) throws IOException{
public Bitmap getBitmap(){return bitmap;}
@Override
public int getWidth() {
return 0;
return bitmap.getWidth();
}

@Override
public int getHeight() {
return 0;
return bitmap.getHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ protected void onCreate(Bundle savedInstanceState) {
//this.renderView = new SurfaceView(this);
//setContentView(this.renderView);
setContentView(this.androidEngine);
clasederelleno clase = new clasederelleno(this.androidEngine);
//StartMenuLogic logicTest = new StartMenuLogic(this.androidEngine);
//clasederelleno clase = new clasederelleno(this.androidEngine);
StartMenuLogic menuLogic = new StartMenuLogic(this.androidEngine);
//LogicTest logicTest = new LogicTest(this.androidEngine);

try {
this.androidEngine.setState(clase);
this.androidEngine.setState(menuLogic);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 8d5c401

Please sign in to comment.