mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-23 22:41:30 +02:00
Android: Implements drawing different text colors
git-svn-id: trunk@34893 -
This commit is contained in:
parent
6bad21a6c1
commit
921aebcc60
@ -302,12 +302,12 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
||||
|
||||
// input: String lcltext, int lclwidth, int lclheight
|
||||
// output: lclbitmap
|
||||
public void LCLDoDrawText()
|
||||
public void LCLDoDrawText(int ATextColor)
|
||||
{
|
||||
lclbitmap = Bitmap.createBitmap(lclwidth, lclheight, Bitmap.Config.ARGB_8888);
|
||||
Canvas localcanvas = new Canvas(lclbitmap);
|
||||
Paint localpaint = new Paint();
|
||||
localpaint.setColor(Color.BLACK);
|
||||
localpaint.setColor(ATextColor);
|
||||
localpaint.setTextSize(lcltextsize);
|
||||
localpaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
||||
localcanvas.drawColor(Color.TRANSPARENT); // TRANSPARENT
|
||||
|
@ -83,6 +83,8 @@ object Form1: TForm1
|
||||
Top = 223
|
||||
Width = 43
|
||||
Caption = 'Label1'
|
||||
Font.Color = clBlue
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
end
|
||||
|
@ -8,13 +8,25 @@ uses
|
||||
// rtl+ftl
|
||||
Types, Classes, SysUtils,
|
||||
fpimage, fpcanvas, ctypes,
|
||||
// Android headers
|
||||
jni,
|
||||
// Custom Drawn Canvas
|
||||
IntfGraphics, lazcanvas,
|
||||
//
|
||||
GraphType, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc,
|
||||
GraphType, Controls, Graphics, LCLMessageGlue, WSControls, LCLType, LCLProc,
|
||||
customdrawnproc;
|
||||
|
||||
function FPColorToAndroidColor(AValue: TFPColor): jint;
|
||||
|
||||
implementation
|
||||
|
||||
// Android color is in the format: Alpha-Red-Green-Blue
|
||||
function FPColorToAndroidColor(AValue: TFPColor): jint;
|
||||
begin
|
||||
Result:= $FF000000 or ((AValue.Blue shr 8) and $ff)
|
||||
or (AValue.Green and $ff00)
|
||||
or ((AValue.Red shl 8) and $ff0000);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -442,7 +442,7 @@ begin
|
||||
// Read all method IDs
|
||||
javaMethod_LCLDoGetTextBounds := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoGetTextBounds', '()V');
|
||||
javaMethod_LCLDoGetTextPartialWidths := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoGetTextPartialWidths', '()V');
|
||||
javaMethod_LCLDoDrawText := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDrawText', '()V');
|
||||
javaMethod_LCLDoDrawText := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDrawText', '(I)V');
|
||||
javaMethod_LCLDoShowMessageBox := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoShowMessageBox', '()V');
|
||||
javaMethod_LCLDoCreateTimer := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoCreateTimer', '()V');
|
||||
javaMethod_LCLDoDestroyTimer := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDestroyTimer', '()V');
|
||||
|
@ -2187,6 +2187,8 @@ var
|
||||
lWidth, lHeight: jint;
|
||||
lDestCanvas: TLazCanvas;
|
||||
lFontSize: Integer;
|
||||
// array for the parameters
|
||||
lParams: array[0..0] of JValue;
|
||||
begin
|
||||
{$ifdef VerboseCDText}
|
||||
DebugLn(Format(':>[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s X=%d Y=%d',
|
||||
@ -2217,7 +2219,8 @@ begin
|
||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
|
||||
|
||||
// Call the method to draw the text
|
||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText);
|
||||
lParams[0].i := FPColorToAndroidColor(lDestCanvas.Font.FPColor);
|
||||
javaEnvRef^^.CallVoidMethodA(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText, @lParams[0]);
|
||||
|
||||
// Get the bitmap with the text
|
||||
lJavaBitmap := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityObject, javaField_lclbitmap);
|
||||
|
Loading…
Reference in New Issue
Block a user