Skip to content
Open
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
213 changes: 176 additions & 37 deletions com/watabou/noosa/BitmapText.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2012-2015 Oleg Dolya
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -39,6 +39,8 @@ public class BitmapText extends Visual {

protected boolean dirty = true;

protected static char INVALID_CHAR = ' ';

public BitmapText() {
this( "", null );
}
Expand Down Expand Up @@ -112,7 +114,7 @@ protected void updateVertices() {
RectF rect = font.get( text.charAt( i ) );

if (rect == null) {
rect=null;
rect = font.get(INVALID_CHAR);
}
float w = font.width( rect );
float h = font.height( rect );
Expand Down Expand Up @@ -171,6 +173,10 @@ public void measure() {
for (int i=0; i < length; i++) {
RectF rect = font.get( text.charAt( i ) );

//Corrigido
if (rect == null) {
rect = font.get(INVALID_CHAR);
}
float w = font.width( rect );
float h = font.height( rect );

Expand Down Expand Up @@ -207,13 +213,28 @@ public void text( String str ) {
}

public static class Font extends TextureFilm {
public static final String SPECIAL_CHAR =
"àáâäãąèéêëęìíîïòóôöõùúûüñńçćłśźż";

public static final String SPECIAL_CHAR_UPPER =
"ÀÁÂÄÃĄÈÉÊËĘÌÍÎÏÒÓÔÖÕÙÚÛÜÑŃÇĆŁŚŹŻºß";

public static final String LATIN_UPPER =
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ";
" !¡\"#$%&'()*+,-./0123456789:;<=>?¿@ABCDEFGHIJKLMNOPQRSTUVWXYZ";

public static final String LATIN_FULL = LATIN_UPPER +
"[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F";

public static final String CYRILLIC_UPPER =
"БГДЖЗИЙЛПУФЦЧШЩЪЫЬЭЮЯ"; //"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";

public static final String CYRILLIC_LOWER =
"бвгджзийлмнптуфцчшщъыьэюя";//"абвгдеёжзийклмнопрстуфхцчшщъыьэюя";

public static final String LATIN_FULL =
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007F";
public static final String CYRILLIC =CYRILLIC_UPPER+CYRILLIC_LOWER;

public static final String ALL_CHARS = LATIN_FULL+SPECIAL_CHAR+SPECIAL_CHAR_UPPER+CYRILLIC;

public SmartTexture texture;

public float tracking = 0;
Expand All @@ -223,6 +244,8 @@ public static class Font extends TextureFilm {

public float lineHeight;

private boolean endOfRow = false;

protected Font( SmartTexture tx ) {
super( tx );

Expand All @@ -238,7 +261,7 @@ public Font( SmartTexture tx, int width, int height, String chars ) {

texture = tx;

autoUppercase = chars.equals( LATIN_UPPER );
autoUppercase = chars.equals( LATIN_UPPER+SPECIAL_CHAR_UPPER+CYRILLIC_UPPER );

int length = chars.length();

Expand All @@ -262,52 +285,114 @@ public Font( SmartTexture tx, int width, int height, String chars ) {
lineHeight = baseLine = height;
}

protected void splitBy( Bitmap bitmap, int height, int color, String chars ) {
private int findNextEmptyLine(Bitmap bitmap, int startFrom, int color){
int width = bitmap.getWidth();
int height = bitmap.getHeight();

autoUppercase = chars.equals( LATIN_UPPER );
int length = chars.length();
int nextEmptyLine = startFrom;

for(nextEmptyLine = startFrom; nextEmptyLine < height; ++nextEmptyLine){
boolean lineEmpty = true;
for(int i = 0;i<width; ++i){
lineEmpty = (bitmap.getPixel (i, nextEmptyLine ) == color) && lineEmpty;
if(!lineEmpty){
break;
}
}
if(lineEmpty){
break;
}
}
return nextEmptyLine;
}

private boolean isColumnEmpty(Bitmap bitmap, int x, int sy, int ey, int color){
for(int j = sy; j < ey; ++j){
if(bitmap.getPixel(x, j) != color){
return false;
}
}
return true;
}

private int findNextCharColumn(Bitmap bitmap, int sx, int sy, int ey, int color){
int width = bitmap.getWidth();
float vHeight = (float)height / bitmap.getHeight();

int pos;
int nextEmptyColumn;
// find first empty column
for(nextEmptyColumn = sx; nextEmptyColumn < width; ++nextEmptyColumn){
if(isColumnEmpty(bitmap,nextEmptyColumn, sy, ey, color)){
break;
}
}

int nextCharColumn;

spaceMeasuring:
for (pos=0; pos < width; pos++) {
for (int j=0; j < height; j++) {
if (bitmap.getPixel( pos, j ) != color) {
break spaceMeasuring;
}
for(nextCharColumn = nextEmptyColumn; nextCharColumn < width; ++nextCharColumn){
if(!isColumnEmpty(bitmap,nextCharColumn, sy, ey, color)){
break;
}
}
add( ' ', new RectF( 0, 0, (float)pos / width, vHeight ) );

for (int i=0; i < length; i++) {
if(nextCharColumn == width){
endOfRow = true;
return nextEmptyColumn - 1;
}

return nextCharColumn-1;
}


protected void splitBy( Bitmap bitmap, int height, int color, String chars ) {

autoUppercase = chars.equals( LATIN_UPPER );
int length = chars.length();

int b_width = bitmap.getWidth();
int b_height = bitmap.getHeight();

int charsProcessed = 0;
int lineTop = 0;
int lineBottom = 0;

while(lineBottom<b_height){
while(lineTop==findNextEmptyLine(bitmap, lineTop, color) && lineTop<b_height) {
lineTop++;
}
lineBottom = findNextEmptyLine(bitmap, lineTop, color);

int charColumn = 0;
int charBorder = 0;

char ch = chars.charAt( i );
if (ch == ' ') {
continue;
} else {
endOfRow = false;
while (! endOfRow){
if(charsProcessed == length){
break;
}

boolean found;
int separator = pos;
charBorder = findNextCharColumn(bitmap,charColumn+1,lineTop,lineBottom,color);

do {
if (++separator >= width) {
break;
}
found = true;
for (int j=0; j < height; j++) {
if (bitmap.getPixel( separator, j ) != color) {
found = false;
int glyphBorder = charBorder;
if(chars.charAt(charsProcessed) != 32) {

for (;glyphBorder > charColumn + 1; --glyphBorder) {
if( !isColumnEmpty(bitmap,glyphBorder, lineTop, lineBottom, color)) {
break;
}
}
} while (!found);
glyphBorder++;
}

add( ch, new RectF( (float)pos / width, 0, (float)separator / width, vHeight ) );
pos = separator + 1;
add( chars.charAt(charsProcessed),
new RectF( (float)(charColumn)/b_width,
(float)lineTop/b_height,
(float)(glyphBorder)/b_width,
(float)lineBottom/b_height ) );
++charsProcessed;
charColumn = charBorder;
}

lineTop = lineBottom+1;
}

lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) );
Expand All @@ -326,7 +411,61 @@ public static Font colorMarked( Bitmap bmp, int height, int color, String chars
}

public RectF get( char ch ) {
return super.get( autoUppercase ? Character.toUpperCase( ch ) : ch );

//Replace Cyrilic Chars(only equal Cyrillic to Latin)
//АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ
//абвгдеёжзийклмнопрстуфхцчшщъыьэюя
if ((ch == 1025)||(ch == 1105) || ((1040 <= ch)&& (ch <= 1103))){
switch (ch) {
case 'А': ch='A'; break; case 'а': ch='a'; break;
case 'В': ch='B'; break;
case 'Е': ch='E'; break; case 'е': ch='e'; break;
case 'Ё': ch='Ë'; break; case 'ё': ch='ë'; break;
case 'К': ch='K'; break; case 'к': ch='k'; break;
case 'М': ch='M'; break;
case 'Н': ch='H'; break;
case 'О': ch='O'; break; case 'о': ch='o'; break;
case 'Р': ch='P'; break; case 'р': ch='p'; break;
case 'С': ch='C'; break; case 'с': ch='c'; break;
case 'Т': ch='T'; break;
case 'Х': ch='X'; break; case 'х': ch='x'; break;
}
}

RectF rec = super.get( autoUppercase ? Character.toUpperCase(ch) : ch );

//Fix for fonts without accentuation
if ((rec == null) && (ch > 126)){
char tmp = ch;
String str = (ch+"")
.replaceAll("[àáâäãą]", "a")
.replaceAll("[èéêëę]", "e")
.replaceAll("[ìíîï]", "i")
.replaceAll("[òóôöõ]", "o")
.replaceAll("[ùúûü]", "u")
.replaceAll("[ÀÁÂÄÃĄ]", "A")
.replaceAll("[ÈÉÊËĘ]", "E")
.replaceAll("[ÌÍÎÏ]", "I")
.replaceAll("[ÒÓÔÖÕ]", "O")
.replaceAll("[ÙÚÛÜ]", "U")
.replaceAll("[çć]", "c")
.replaceAll("[ÇĆ]", "C")
.replaceAll("[ñń]", "n")
.replaceAll("[ÑŃ]", "N")
.replaceAll("[źż]", "z")
.replaceAll("[ŹŻ]", "Z")
.replace( 'ß', 'B')
.replace( 'ł', 'l')
.replace( 'Ł', 'L')
.replace( 'ś', 's')
.replace( 'Ś', 'S')
;

tmp = str.charAt(0);
rec = super.get(autoUppercase ? Character.toUpperCase(tmp) : tmp);
}

return rec;
}
}
}
13 changes: 11 additions & 2 deletions com/watabou/noosa/BitmapTextMultiline.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ protected void updateVertices() {

for (int k=0; k < length; k++) {
RectF rect = font.get( word.charAt( k ) );


//Corrigido
if (rect == null) {
rect = font.get(INVALID_CHAR);
}

float w = font.width( rect );
float h = font.height( rect );

Expand Down Expand Up @@ -148,6 +153,10 @@ private void getWordMetrics( String word, PointF metrics ) {
for (int i=0; i < length; i++) {

RectF rect = font.get( word.charAt( i ) );
//Corrigido
if (rect == null) {
rect = font.get(INVALID_CHAR);
}
w += font.width( rect ) + (w > 0 ? font.tracking : 0);
h = Math.max( h, font.height( rect ) );
}
Expand Down Expand Up @@ -318,4 +327,4 @@ public ArrayList<BitmapText> split() {
return lines;
}
}
}
}
39 changes: 39 additions & 0 deletions com/watabou/noosa/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.watabou.noosa;

import java.util.ArrayList;
import java.util.Locale;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
Expand All @@ -33,7 +34,12 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
Expand Down Expand Up @@ -305,4 +311,37 @@ protected void update() {
public static void vibrate( int milliseconds ) {
((Vibrator)instance.getSystemService( VIBRATOR_SERVICE )).vibrate( milliseconds );
}

public void useLocale(String lang) {
if (lang.equals("def")){
return;
}
String lan = lang.split("_")[0];
String reg = (lang.split("_").length > 1)? lang.split("_")[1]: "";

Locale locale = new Locale(lan, reg);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}

public void doRestart() {
Intent i = instance.getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

int piId = 123456;
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), piId, i, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getBaseContext().getSystemService(ContextWrapper.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pi);

System.exit(0);
}

public static String getVar(int id){
return instance.getApplicationContext().getResources().getString(id);
}

public static String[] getVars(int id){
return instance.getApplicationContext().getResources().getStringArray(id);
}
}
2 changes: 2 additions & 0 deletions com/watabou/noosa/audio/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum Sample implements SoundPool.OnLoadCompleteListener {

public static final int MAX_STREAMS = 8;

@SuppressWarnings("deprecation")
protected SoundPool pool =
new SoundPool( MAX_STREAMS, AudioManager.STREAM_MUSIC, 0 );

Expand All @@ -42,6 +43,7 @@ public enum Sample implements SoundPool.OnLoadCompleteListener {

private boolean enabled = true;

@SuppressWarnings("deprecation")
public void reset() {

pool.release();
Expand Down
Loading