SRL Archive - OSR Help

Fonts & TImage


Valithor

2013-06-26 22:34:03

Here's a quick question that I hope that can be solved quickly.
How would I write black text on a Canvas? My current code looks like this.

program new;
var
Buffer: Integer;

procedure DrawOnBuffer;
var
text, Width, Height: Integer;
Font: TFont;

begin
Buffer:= BitmapFromString(200, 200, '');
RectangleBitmap(Buffer, IntToBox(0, 0, 199, 199), 16777215); //Comment this line
//and you will see text
Font := TFont.Create;
Font.Name := 'Courier New';
Font.Size := 10;
Font.Color:= 0;
Font.Style := [];
LoadSystemFont(Font,'test');


text:= BitmapFromText('Hello', 'test');
GetBitmapSize(text, Width, Height);
SetTransparentcolor (text, clBlack);
FastDrawTransparent(round ((200 * 0.5) - (Width/ 2)), 12, text, Buffer);
FreeBitmap(text);
Font.free;
end;

procedure CreateCanvas;
begin
DisplayDebugImgWindow(200, 200);
DrawOnBuffer;
DrawBitmapDebugImg(Buffer);
FreeBitmap(Buffer);
end;

begin
SetupSRL;
CreateCanvas;
end.

Is there anyway where I can turn the font color black? Also…
Out of curiousity, is there a way to create transparent colors for TImages (bitmaps) that are on a form?

ActualNoob

2013-06-28 15:46:35

From: Valithor
Here's a quick question that I hope that can be solved quickly.
How would I write black text on a Canvas? My current code looks like this.

program new;
var
Buffer: Integer;

procedure DrawOnBuffer;
var
text, Width, Height: Integer;
Font: TFont;

begin
Buffer:= BitmapFromString(200, 200, '');
RectangleBitmap(Buffer, IntToBox(0, 0, 199, 199), 16777215); //Comment this line
//and you will see text
Font := TFont.Create;
Font.Name := 'Courier New';
Font.Size := 10;
Font.Color:= 0;
Font.Style := [];
LoadSystemFont(Font,'test');


text:= BitmapFromText('Hello', 'test');
GetBitmapSize(text, Width, Height);
SetTransparentcolor (text, clBlack);
FastDrawTransparent(round ((200 * 0.5) - (Width/ 2)), 12, text, Buffer);
FreeBitmap(text);
Font.free;
end;

procedure CreateCanvas;
begin
DisplayDebugImgWindow(200, 200);
DrawOnBuffer;
DrawBitmapDebugImg(Buffer);
FreeBitmap(Buffer);
end;

begin
SetupSRL;
CreateCanvas;
end.

Is there anyway where I can turn the font color black? Also…
Out of curiousity, is there a way to create transparent colors for TImages (bitmaps) that are on a form?


Hm.. i was also wondering how to make transparent images on forms. I think you can just set the image the same colour as the background or another way which i tried was to set the part of the image you want transparent to the same image on the background of your form. Maybe someone knows a better way to do it. Tell me if script below works.

Click start bot once and wait for the monkey to disappear. you can also click close bot and a picture appears.
[ATTACH]21813[/ATTACH]

Valithor

2013-07-03 11:28:55

From: ActualNoob
Hm.. i was also wondering how to make transparent images on forms. I think you can just set the image the same colour as the background or another way which i tried was to set the part of the image you want transparent to the same image on the background of your form. Maybe someone knows a better way to do it.


Actually, I think that is a pretty good work around! The only issue that I found is that some of your coordinates may be off. Because I tend to get a lot of distortion when your images appear. I'll have to look through your code to see if I can improve upon it but that seems to work (granted that we can fix the distortion issue). Image provided.


Also, you have A LOT of variables that are never called, and you don't free some bitmaps. Debug will read…

The following bitmaps were not freed: [0, 1, 2].
Sometimes the "buffer" and Bitmap[5] aren't freed. One final note that should be considered. If there is a window on top of the form then, it will also grab parts of that window and print it on your form. Do you know of any way to take from ONLY the form?

EDIT: Actually, it looks like the above mentioned distortion comes from the way you are drawing the bitmaps on the Form. I was having a similar issue earlier while experimenting with Canvases. If you draw a bitmap on a canvas you'll get multiple layered copies. Not exactly the desired effect.

This can be seen from lines 270 to 283.

EDIT 2: Though, the that method would work excellently if you wanted to print a static (not moving) image. Like you do with your "character" image. Your "GetImg()" function works great, though if you want it to print "seamlessly" you'll need to change the final line to:
DrawBitmap(buffer, dsgnForm.CANVAS, x - 4, y - 30);

ActualNoob

2013-07-03 15:56:21

Thanks for testing it out and giving me some advice. I have only begun coding for 2-3 weeks so iam still trying stuff out on my own so my code is very messy iam glad you could read it though. I was afraid this would happen. The distortions are caused by you using a different computer theme than mine( the icons on the top cause a different sized bar), so the offset x-4, y-30 are different to mine.

DrawBitmap(buffer, dsgnForm.CANVAS, x +dsgnForm.ClientWidth - dsgnForm.Width , y + dsgnForm.ClientHeight- dsgnForm.Height);

The above code should be correct, but for some reason they(dsgnForm.clientWidth and dsgnForm.Width) return the same value which isnt supposed to happen. I tried a work around and i cleaned up unused variables and freed the bitmaps. I also took your advice and it draws it onto a TImage now so if you drag a window on top it wont disappear.

Sometimes the "buffer" and Bitmap[5] aren't freed. One final note that should be considered. If there is a window on top of the form then, it will also grab parts of that window and print it on your form. Do you know of any way to take from ONLY the form?

I will look at it. for some reason it still does it.

attached wrong file

[ATTACH]21865[/ATTACH]