Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Writing text with DelphiX simplified

Title: Writing text with DelphiX simplified. Question: It takes many lines to write one simple line of text, is there an easier way to do it with one line? Answer: You will need DelphiX for Delphi for this to be of any use. Here is some example code i've been using in my game to write text out instead of always having to go through the same massive steps for every single line. It's a very simple thing to do, but after looking at other peoples source code, i've found they don't actually make shortcuts, they actually add 10% more lines of code cutting and pasting entire process over! Basic overview.. writeit(X location, Y location, TColor code, String to write!); // Writes text out .. // // Example code .. writeit(10,10,$00FFFFFF,'Test!'); // // Remember.. Delphi TColor is backwards from the norm Hex codes you might // use in web pages.. $00BBGGRR So.. $00FF0000 is Blue, $0000FF00 is Green, // and $000000FF is Red. I've got some pages of color charts made that I look // up for specific colors and then just type them in backwards basically.. // // procedure writeit(xwrite: Integer; ywrite: Integer; textcol: TColor; textstring: string); begin Form1.DXDraw1.Surface.Canvas.Font.Style := [fsBold]; Form1.DXDraw1.Surface.Canvas.Brush.Style:=bsClear; Form1.DXDraw1.Surface.Canvas.Font.Color:=textcol; Form1.DXDraw1.Surface.Canvas.TextOut(xwrite,ywrite,textstring); Form1.DXDraw1.Surface.Canvas.Release; end; // // Writes text out, this time with a black shadow below the text. // // Note: This doesn't always look good with certain colors, so play with it. // // You could modify this to chose the shadow color in the procedure also.. // procedure swriteit(xwrite: Integer; ywrite: Integer; textcol: TColor; textstring: string); begin Form1.DXDraw1.Surface.Canvas.Font.Style := [fsBold]; Form1.DXDraw1.Surface.Canvas.Brush.Style:=bsClear; //Draw the shadow FIRST. Here it's set to black.. Form1.DXDraw1.Surface.Canvas.Font.Color:=$00000000; Form1.DXDraw1.Surface.Canvas.TextOut(xwrite+1,ywrite+1,textstring); //Now draw the actual text over the shadow.. Form1.DXDraw1.Surface.Canvas.Font.Color:=textcol; Form1.DXDraw1.Surface.Canvas.TextOut(xwrite,ywrite,textstring); Form1.DXDraw1.Surface.Canvas.Release; end;