Adjust graphics from j3270 changes
Build and Test a3270 / Build Android APK (push) Successful in 6m18s
Build and Test a3270 / Build Android APK (push) Successful in 6m18s
This commit is contained in:
@@ -9,3 +9,4 @@ captures/
|
|||||||
.cxx
|
.cxx
|
||||||
*.jar
|
*.jar
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
*.txt
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ if [ ! -d "$J3270_PATH/lib3270j" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Building debug APK..."
|
echo "Building debug APK..."
|
||||||
./gradlew assembleDebug
|
./gradlew assembleDebug --no-daemon
|
||||||
|
|
||||||
APK_PATH="$SCRIPT_DIR/build/outputs/apk/debug/a3270-debug.apk"
|
APK_PATH="$SCRIPT_DIR/build/outputs/apk/debug/a3270-debug.apk"
|
||||||
if [ -f "$APK_PATH" ]; then
|
if [ -f "$APK_PATH" ]; then
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package haus.nightmare.a3270.graphics
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.RectF
|
||||||
|
import haus.nightmare.lib3270j.graphics.PixelBuffer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Android bridge for translating lib3270j PixelBuffer into Android Bitmaps and rendering onto Canvas.
|
||||||
|
*/
|
||||||
|
object AndroidCanvasRenderer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a PixelBuffer into an Android Bitmap using ARGB_8888 configuration.
|
||||||
|
*/
|
||||||
|
fun toBitmap(buffer: PixelBuffer?): Bitmap? {
|
||||||
|
if (buffer == null) return null
|
||||||
|
val w = buffer.width
|
||||||
|
val h = buffer.height
|
||||||
|
if (w <= 0 || h <= 0) return null
|
||||||
|
val pixels = buffer.pixels ?: return null
|
||||||
|
return Bitmap.createBitmap(pixels, w, h, Bitmap.Config.ARGB_8888)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the given PixelBuffer onto an Android Canvas scaled to the destination rectangle.
|
||||||
|
*/
|
||||||
|
fun drawPixelBuffer(
|
||||||
|
canvas: Canvas,
|
||||||
|
buffer: PixelBuffer?,
|
||||||
|
dstRect: RectF,
|
||||||
|
paint: Paint? = null
|
||||||
|
) {
|
||||||
|
val bmp = toBitmap(buffer) ?: return
|
||||||
|
canvas.drawBitmap(bmp, null, dstRect, paint)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the PixelBuffer contents into an existing mutable Bitmap.
|
||||||
|
*/
|
||||||
|
fun copyIntoBitmap(buffer: PixelBuffer, target: Bitmap) {
|
||||||
|
val pixels = buffer.pixels ?: return
|
||||||
|
val w = minOf(buffer.width, target.width)
|
||||||
|
val h = minOf(buffer.height, target.height)
|
||||||
|
if (w <= 0 || h <= 0) return
|
||||||
|
target.setPixels(pixels, 0, buffer.width, 0, 0, w, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user