Merge "Renderscript samples. Merged two model related projects. Cleanup."
This commit is contained in:
committed by
Android (Google) Code Review
commit
3e5ea4a814
@@ -18,6 +18,8 @@ package android.renderscript;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.AssetManager;
|
||||
@@ -30,10 +32,100 @@ import android.util.TypedValue;
|
||||
**/
|
||||
public class Font extends BaseObj {
|
||||
|
||||
//These help us create a font by family name
|
||||
private static final String[] sSansNames = {
|
||||
"sans-serif", "arial", "helvetica", "tahoma", "verdana"
|
||||
};
|
||||
|
||||
private static final String[] sSerifNames = {
|
||||
"serif", "times", "times new roman", "palatino", "georgia", "baskerville",
|
||||
"goudy", "fantasy", "cursive", "ITC Stone Serif"
|
||||
};
|
||||
|
||||
private static final String[] sMonoNames = {
|
||||
"monospace", "courier", "courier new", "monaco"
|
||||
};
|
||||
|
||||
private static class FontFamily {
|
||||
String[] mNames;
|
||||
String mNormalFileName;
|
||||
String mBoldFileName;
|
||||
String mItalicFileName;
|
||||
String mBoldItalicFileName;
|
||||
}
|
||||
|
||||
private static Map<String, FontFamily> sFontFamilyMap;
|
||||
|
||||
public enum Style {
|
||||
NORMAL,
|
||||
BOLD,
|
||||
ITALIC,
|
||||
BOLD_ITALIC;
|
||||
}
|
||||
|
||||
private static void addFamilyToMap(FontFamily family) {
|
||||
for(int i = 0; i < family.mNames.length; i ++) {
|
||||
sFontFamilyMap.put(family.mNames[i], family);
|
||||
}
|
||||
}
|
||||
|
||||
private static void initFontFamilyMap() {
|
||||
sFontFamilyMap = new HashMap<String, FontFamily>();
|
||||
|
||||
FontFamily sansFamily = new FontFamily();
|
||||
sansFamily.mNames = sSansNames;
|
||||
sansFamily.mNormalFileName = "DroidSans.ttf";
|
||||
sansFamily.mBoldFileName = "DroidSans-Bold.ttf";
|
||||
sansFamily.mItalicFileName = "DroidSans.ttf";
|
||||
sansFamily.mBoldItalicFileName = "DroidSans-Bold.ttf";
|
||||
addFamilyToMap(sansFamily);
|
||||
|
||||
FontFamily serifFamily = new FontFamily();
|
||||
serifFamily.mNames = sSerifNames;
|
||||
serifFamily.mNormalFileName = "DroidSerif-Regular.ttf";
|
||||
serifFamily.mBoldFileName = "DroidSerif-Bold.ttf";
|
||||
serifFamily.mItalicFileName = "DroidSerif-Italic.ttf";
|
||||
serifFamily.mBoldItalicFileName = "DroidSerif-BoldItalic.ttf";
|
||||
addFamilyToMap(serifFamily);
|
||||
|
||||
FontFamily monoFamily = new FontFamily();
|
||||
monoFamily.mNames = sMonoNames;
|
||||
monoFamily.mNormalFileName = "DroidSansMono.ttf";
|
||||
monoFamily.mBoldFileName = "DroidSansMono.ttf";
|
||||
monoFamily.mItalicFileName = "DroidSansMono.ttf";
|
||||
monoFamily.mBoldItalicFileName = "DroidSansMono.ttf";
|
||||
addFamilyToMap(monoFamily);
|
||||
}
|
||||
|
||||
static {
|
||||
initFontFamilyMap();
|
||||
}
|
||||
|
||||
static String getFontFileName(String familyName, Style style) {
|
||||
FontFamily family = sFontFamilyMap.get(familyName);
|
||||
if(family != null) {
|
||||
switch(style) {
|
||||
case NORMAL:
|
||||
return family.mNormalFileName;
|
||||
case BOLD:
|
||||
return family.mBoldFileName;
|
||||
case ITALIC:
|
||||
return family.mItalicFileName;
|
||||
case BOLD_ITALIC:
|
||||
return family.mBoldItalicFileName;
|
||||
}
|
||||
}
|
||||
// Fallback if we could not find the desired family
|
||||
return "DroidSans.ttf";
|
||||
}
|
||||
|
||||
Font(int id, RenderScript rs) {
|
||||
super(id, rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a specific file name as an argument
|
||||
*/
|
||||
static public Font create(RenderScript rs, Resources res, String fileName, int size)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
@@ -43,7 +135,7 @@ public class Font extends BaseObj {
|
||||
int fontId = rs.nFontCreateFromFile(fileName, size, dpi);
|
||||
|
||||
if(fontId == 0) {
|
||||
throw new IllegalStateException("Load loading a font");
|
||||
throw new IllegalStateException("Failed loading a font");
|
||||
}
|
||||
Font rsFont = new Font(fontId, rs);
|
||||
|
||||
@@ -55,4 +147,19 @@ public class Font extends BaseObj {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts one of the following family names as an argument
|
||||
* and will attemp to produce the best match with a system font
|
||||
* "sans-serif" "arial" "helvetica" "tahoma" "verdana"
|
||||
* "serif" "times" "times new roman" "palatino" "georgia" "baskerville"
|
||||
* "goudy" "fantasy" "cursive" "ITC Stone Serif"
|
||||
* "monospace" "courier" "courier new" "monaco"
|
||||
* Returns default font if no match could be found
|
||||
*/
|
||||
static public Font createFromFamily(RenderScript rs, Resources res, String familyName, Style fontStyle, int size)
|
||||
throws IllegalArgumentException {
|
||||
String fileName = getFontFileName(familyName, fontStyle);
|
||||
return create(rs, res, fileName, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,13 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SceneGraph"
|
||||
android:label="SceneGraph"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.scenegraph;
|
||||
package com.android.modelviewer;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.scenegraph;
|
||||
package com.android.modelviewer;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.scenegraph;
|
||||
package com.android.modelviewer;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.scenegraph;
|
||||
package com.android.modelviewer;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#pragma version(1)
|
||||
|
||||
#pragma rs java_package_name(com.android.scenegraph)
|
||||
#pragma rs java_package_name(com.android.modelviewer)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
#include "transform_def.rsh"
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#pragma version(1)
|
||||
|
||||
#pragma rs java_package_name(com.android.scenegraph)
|
||||
#pragma rs java_package_name(com.android.modelviewer)
|
||||
|
||||
#include "transform_def.rsh"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#pragma version(1)
|
||||
|
||||
#pragma rs java_package_name(com.android.scenegraph)
|
||||
#pragma rs java_package_name(com.android.modelviewer)
|
||||
|
||||
#define TRANSFORM_NONE 0
|
||||
#define TRANSFORM_TRANSLATE 1
|
||||
@@ -24,7 +24,7 @@ LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||
|
||||
LOCAL_PACKAGE_NAME := SceneGraph
|
||||
LOCAL_PACKAGE_NAME := Samples
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.scenegraph">
|
||||
<application android:label="SceneGraph">
|
||||
<activity android:name="SceneGraph"
|
||||
package="com.android.samples">
|
||||
<application android:label="Samples">
|
||||
<activity android:name="RsList"
|
||||
android:label="RsList"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
71
libs/rs/java/Samples/src/com/android/samples/RsList.java
Normal file
71
libs/rs/java/Samples/src/com/android/samples/RsList.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.samples;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings.System;
|
||||
import android.util.Config;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.lang.Runtime;
|
||||
|
||||
public class RsList extends Activity {
|
||||
|
||||
private RsListView mView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
// Create our Preview view and set it as the content of our
|
||||
// Activity
|
||||
mView = new RsListView(this);
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onResume();
|
||||
mView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onPause();
|
||||
mView.onPause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
145
libs/rs/java/Samples/src/com/android/samples/RsListRS.java
Normal file
145
libs/rs/java/Samples/src/com/android/samples/RsListRS.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.samples;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class RsListRS {
|
||||
|
||||
private final int STATE_LAST_FOCUS = 1;
|
||||
|
||||
private static final String[] DATA_LIST = {
|
||||
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
|
||||
"Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
|
||||
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
|
||||
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
|
||||
"Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
|
||||
"Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
|
||||
"British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
|
||||
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
|
||||
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
|
||||
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
|
||||
"Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
|
||||
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
|
||||
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
|
||||
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
|
||||
"Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
|
||||
"French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
|
||||
"Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
|
||||
"Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
|
||||
"Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
|
||||
"Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
|
||||
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
|
||||
"Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
|
||||
"Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
|
||||
"Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
|
||||
"Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
|
||||
"Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
|
||||
"Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
|
||||
"Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
|
||||
"Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
|
||||
"Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
|
||||
"Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
|
||||
"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
|
||||
"Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
|
||||
"Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
|
||||
"Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
|
||||
"The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
|
||||
"Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
|
||||
"Ukraine", "United Arab Emirates", "United Kingdom",
|
||||
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
|
||||
"Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
|
||||
"Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
|
||||
};
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
public RsListRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res, int width, int height) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
initRS();
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Font mItalic;
|
||||
|
||||
ScriptField_ListAllocs_s mListAllocs;
|
||||
|
||||
private ScriptC_Rslist mScript;
|
||||
|
||||
int mLastX;
|
||||
int mLastY;
|
||||
|
||||
public void onActionDown(int x, int y) {
|
||||
mScript.set_gDY(0.0f);
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
|
||||
public void onActionMove(int x, int y) {
|
||||
int dx = mLastX - x;
|
||||
int dy = mLastY - y;
|
||||
|
||||
if(Math.abs(dy) <= 2) {
|
||||
dy = 0;
|
||||
}
|
||||
|
||||
mScript.set_gDY(dy);
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_Rslist(mRS, mRes, R.raw.rslist, true);
|
||||
|
||||
mListAllocs = new ScriptField_ListAllocs_s(mRS, DATA_LIST.length);
|
||||
for(int i = 0; i < DATA_LIST.length; i ++) {
|
||||
ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
|
||||
listElem.text = Allocation.createFromString(mRS, DATA_LIST[i]);
|
||||
mListAllocs.set(listElem, i, false);
|
||||
}
|
||||
|
||||
mListAllocs.copyAll();
|
||||
|
||||
mScript.bind_gList(mListAllocs);
|
||||
|
||||
mItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
mRS.contextBindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
98
libs/rs/java/Samples/src/com/android/samples/RsListView.java
Normal file
98
libs/rs/java/Samples/src/com/android/samples/RsListView.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.samples;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class RsListView extends RSSurfaceView {
|
||||
|
||||
public RsListView(Context context) {
|
||||
super(context);
|
||||
//setFocusable(true);
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private RsListRS mRender;
|
||||
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
if (mRS == null) {
|
||||
mRS = createRenderScript(true);
|
||||
mRS.contextSetSurface(w, h, holder.getSurface());
|
||||
mRender = new RsListRS();
|
||||
mRender.init(mRS, getResources(), w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
if(mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScript();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
// break point at here
|
||||
// this method doesn't work when 'extends View' include 'extends ScrollView'.
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev)
|
||||
{
|
||||
boolean ret = false;
|
||||
int act = ev.getAction();
|
||||
if (act == ev.ACTION_DOWN) {
|
||||
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
}
|
||||
else if (act == ev.ACTION_MOVE) {
|
||||
mRender.onActionMove((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
73
libs/rs/java/Samples/src/com/android/samples/rslist.rs
Normal file
73
libs/rs/java/Samples/src/com/android/samples/rslist.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma version(1)
|
||||
|
||||
#pragma rs java_package_name(com.android.samples)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
float gDY;
|
||||
|
||||
rs_font gItalic;
|
||||
|
||||
typedef struct ListAllocs_s {
|
||||
rs_allocation text;
|
||||
} ListAllocs;
|
||||
|
||||
ListAllocs *gList;
|
||||
|
||||
#pragma rs export_var(gDY, gItalic, gList)
|
||||
|
||||
void init() {
|
||||
gDY = 0.0f;
|
||||
}
|
||||
|
||||
int textPos = 0;
|
||||
|
||||
int root(int launchID) {
|
||||
|
||||
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
textPos -= (int)gDY*2;
|
||||
gDY *= 0.95;
|
||||
|
||||
rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
|
||||
rsgBindFont(gItalic);
|
||||
color(0.2, 0.2, 0.2, 0);
|
||||
|
||||
rs_allocation listAlloc = rsGetAllocation(gList);
|
||||
int allocSize = rsAllocationGetDimX(listAlloc);
|
||||
|
||||
int width = rsgGetWidth();
|
||||
int height = rsgGetHeight();
|
||||
|
||||
int itemHeight = 80;
|
||||
int currentYPos = itemHeight + textPos;
|
||||
|
||||
for(int i = 0; i < allocSize; i ++) {
|
||||
if(currentYPos - itemHeight > height) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(currentYPos > 0) {
|
||||
rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
|
||||
rsgDrawText(gList[i].text, 30, currentYPos - 32);
|
||||
}
|
||||
currentYPos += itemHeight;
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 286 KiB |
Binary file not shown.
@@ -218,6 +218,7 @@ Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph)
|
||||
|
||||
Font * Font::create(Context *rsc, const char *name, uint32_t fontSize, uint32_t dpi)
|
||||
{
|
||||
rsc->mStateFont.checkInit();
|
||||
Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
|
||||
|
||||
for(uint32_t i = 0; i < activeFonts.size(); i ++) {
|
||||
@@ -513,6 +514,12 @@ void FontState::checkInit()
|
||||
|
||||
initVertexArrayBuffers();
|
||||
|
||||
// We store a string with letters in a rough frequency of occurrence
|
||||
mLatinPrecache = String8(" eisarntolcdugpmhbyfvkwzxjq");
|
||||
mLatinPrecache += String8("EISARNTOLCDUGPMHBYFVKWZXJQ");
|
||||
mLatinPrecache += String8(",.?!()-+@;:`'");
|
||||
mLatinPrecache += String8("0123456789");
|
||||
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
@@ -622,7 +629,7 @@ void FontState::appendMeshQuad(float x1, float y1, float z1,
|
||||
|
||||
uint32_t FontState::getRemainingCacheCapacity() {
|
||||
uint32_t remainingCapacity = 0;
|
||||
float totalPixels = 0;
|
||||
uint32_t totalPixels = 0;
|
||||
for(uint32_t i = 0; i < mCacheLines.size(); i ++) {
|
||||
remainingCapacity += (mCacheLines[i]->mMaxWidth - mCacheLines[i]->mCurrentCol);
|
||||
totalPixels += mCacheLines[i]->mMaxWidth;
|
||||
@@ -666,12 +673,6 @@ void FontState::renderText(const char *text, uint32_t len, uint32_t startIndex,
|
||||
issueDrawCommand();
|
||||
mCurrentQuadIndex = 0;
|
||||
}
|
||||
|
||||
// We store a string with letters in a rough frequency of occurrence
|
||||
mLatinPrecache = String8(" eisarntolcdugpmhbyfvkwzxjq");
|
||||
mLatinPrecache += String8("EISARNTOLCDUGPMHBYFVKWZXJQ");
|
||||
mLatinPrecache += String8(",.?!()-+@;:`'");
|
||||
mLatinPrecache += String8("0123456789");
|
||||
}
|
||||
|
||||
void FontState::renderText(const char *text, int x, int y)
|
||||
|
||||
Reference in New Issue
Block a user