How can draw a string using directX 10? - directx

I'm a newbie in directX and I have a problem with this.
I want to draw a string on the screen but it does not work. I did search on internet and I got some tutorials for this. This is the code:
//Create font
void RealGame::CreateMyFont(LPDIRECT3DDEVICE9 d3ddv)
{
D3DXCreateFont(d3ddv, // the D3D Device
20, // font height
0, // default font width
FW_NORMAL, // font weight
1, // not using MipLevels
false, // italic font
DEFAULT_CHARSET, // default character set
OUT_DEFAULT_PRECIS, // default OutputPrecision,
DEFAULT_QUALITY, // default Quality
DEFAULT_PITCH | FF_DONTCARE, // default pitch and family
L"Arial", // use Facename Arial
&font);
}
//Draw text on screen
void RealGame::DrawGameInfo(LPD3DXSPRITE sp,LPDIRECT3DDEVICE9 d3ddv,LPCWSTR text)
{
RECT textbox;
SetRect(&textbox, 100, 100, 800, 20);
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,0,255);
if(font!=NULL)
font->DrawText(sp, text, -1, &textbox, 0, fontColor );
}
The result is: no text displayed on screen.
Please tell me why and correct my mistakes if i have.
Thank you.
UPDATE:
After change flag to DT_NOCLIP | DT_TOP | DT_LEFT
=> font->DrawText(sp, text, -1, &textbox, DT_NOCLIP | DT_TOP | DT_LEFT,, fontColor );
It works.
Thanks Gnietschow for help.

Related

The effect of BufferType.Normal and BufferType.Spannable for textView

I have this code:
TextView tv1 = FindViewById<TextView>(Resource.Id.textView1);
tv1.Text = "Text";
SpannableString wordtoSpan = new SpannableString(tv1.Text);
wordtoSpan.SetSpan(new UnderlineSpan(), 0, tv1.Text.Length, 0);
tv1.SetText(wordtoSpan, TextView.BufferType.Normal);
Whether I use BufferType.Normal or BufferType.Spannable, A line is drawn below the text,
a line appears below the text. So what is the effect of BufferType.Normal and BufferType.Spannable?
TextView.BufferType:
Normal: normal;
Editable: characters can be appended;
Spannable: use styles in the given character area;
The type of the text buffer that defines the characteristics of the text such as static, styleable, or editable. It could be used for changing the TextView in runtime.
TextView.BufferType.Editable: Insert
TextView tv2 = FindViewById<TextView>(Resource.Id.textView2);
tv2.SetText("Hello", TextView.BufferType.Editable);
var s = tv2.EditableText;
s.Insert(1, " Hello");
OutPut:
TextView.BufferType.Spannable: set the different color in a single Textview
TextView tv3 = FindViewById<TextView>(Resource.Id.textView3);
tv3.Text = "Hello World";
SpannableString wordtoSpan3 = new SpannableString(tv3.Text);
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Red), 0, 5, 0); // "Hello" is red
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Blue), 7, 11, 0); // "orld" is blue
tv3.SetText(wordtoSpan3, TextView.BufferType.Spannable);
Output:

TCPDF create move-able "box" with text without using ln settings

I am trying to create a bit of a unique table in TCPDF as shown below:
Getting the captions, headers and rows setup is easy. The hard part is the "bar".
The bar needs a few things:
Editable X-position
Text
Originally I was trying to use MultiCell; however, I got some weird behavior as shown below:
Multi-Cell:
I believe this is because of the ln settings. If we look at my code you can see that I am trying to create a Cell and then a MultiCell inside of it. Both of these use the have the ln setting to put the next cell below.
I tried setting the MultiCell's ln to 0 (to the right) but it had no visible change.
//multi cell
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
0, //Border
"C", //Text Align
false, //fill, determines if the background is painted or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
After this I found out about TextField. When I tried this I got just as weird behavior...
//text field
// extend TCPF with custom functions
class MYPDF extends TCPDF {
// SCC table
public function SCCTable($headers,$rows) {
// Colors, line width and bold font
$this->SetFillColor(0,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// Header
$num_headers = count($headers);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell(
$headers[$i]->width,
$headers[$i]->height,
$headers[$i]->text,
1,
0,
'C',
1
);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$num_rows = count($rows);
for($i = 0; $i < $num_rows; ++$i){
$this->Cell(//Row
$headers[$i]->width * $num_headers, //Row width should be the sum of all header width.
$rows[$i]->height,
//Row's Text
$this->TextField(
$rows[$i]->text,
$rows[$i]->width,
$rows[$i]->height,
[],
[],
$rows[$i]->x,
$rows[$i]->y
),
1, //Border
2, //ln, 1 = Next cell starts at beginning of new line.
"L" //text align
);
}
}
}
Finally I thought of using the Rect function to create a rectangle and Text to the draw the text. Using variables I could "glue" the Text to the Rectangle; however, the textfield uses the ln setting as well; furthermore, looking at the actual code there is this line:
$this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
Seeing as it creates a cell, then it should run into the same problem as MultiCell, as the only difference between Cell and MultiCell in my case is the ability to change the x-position from the left border.
So I'm stuck with this question: How can I draw a "box" that has text and can be pushed along horizontally?
How this is done is not that important except that images aren't an option.
I realized I didn't actually need to have the original row. I could just make due with the "bar".
$this->MultiCell(
$rows[$i]->width,
$rows[$i]->height,
$rows[$i]->text,
1, //Border
"C", //Text Align
true, //fill, determines if the background is painted (true) or transparent (false).
2, //ln, 1 = Next cell starts at beginning of new line.
$rows[$i]->x,
$rows[$i]->y
);
Though with that said it would still be nice to know how to do with rows...

WriteHTMLCell doesn't change GetY()

I'm trying to work out the height of a WriteHTMLCell box.. I thought I could use the difference between the Y position before and after calling WriteHTMLCell()....
$start_y = $pdf->GetY();
$pdf->WriteHTMLCell(
$w,
0, // min height
$xpos, // XPos
$ypos, // YPos
$text,
1, // border
0, // ln
false, // fill
false, // reseth
"R"
);
$end_y = $pdf->GetY();
..But $start_y always equals $end_y (NB, the x position does move)
The tcpdf manual Says this.. "After the call, the current position moves to the right or to the next line." ... but it doesn't say why it moves to the right and not to the next line.
NB, I have done extensive research. This question may appear similar to Another stack overflow question - However, this is for a different tcpdf call.
The answer was to change the argument $ln to 1
$pdf->WriteHTMLCell(
$w,
0, // min height
$xpos, // XPos
$ypos, // YPos
$text,
1, // border
1, // ln
false, // fill
false, // reseth
"R"
);

Vaadin Alignment with GridLayout to center over cells

I trying to get image and title to be in the center
the login in box works OK
private void createTitle(final AbstractOrderedLayout parentLayout) {
GridLayout layout = new GridLayout(6, 2);
layout.setSpacing(true);
layout.setWidth( 100, Sizeable.Unit.PERCENTAGE );
layout.setHeight( 100, Sizeable.Unit.PERCENTAGE );
parentLayout.addComponent(layout);
parentLayout.setComponentAlignment(layout, Alignment.TOP_CENTER);
Embedded image = new Embedded("", new ClassResource("Icon_25x32.png"));
layout.addComponent(image, 2, 0);
layout.setComponentAlignment(image, Alignment.TOP_CENTER);
Label titleLabel = new Label("YT-100 ATU Control Center");
titleLabel.addStyleName("v-label-largeTitleText");
//layout.addComponent(titleLabel, 3, 1);
layout.addComponent(titleLabel, 3, 1, 4,1);
layout.setComponentAlignment(titleLabel, Alignment.TOP_CENTER);
mUserLayout = new GridLayout(2, 2);
mUserLayout.setSpacing(true);
layout.addComponent(mUserLayout, 5, 0);
layout.setComponentAlignment(mUserLayout, Alignment.MIDDLE_CENTER);
}
why does this not center?
Fixed:
titleLabel.setSizeUndefined();
and
.v-caption-centered, input.centered {
text-align: center;
}
notice that title label has 100% width by default, so it will take the entire width of the containing layout cell. Centering is only meaningful for components that take less width than the containing cell. Hence, you'd need to set the label width to undefined.

How to color text and background separatly for Imagick caption?

I only want to color the caption text, and not the entire caption box (or background).
Before Imagemagick 6.3.7 I could use this code to have a red colored text :
$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->colorizeImage('#ff0000',1.0);
I have upgraded because I need to set a font and a font size with the following code :
$im->setFont("somefont.ttf");
$im->setpointsize(72);
Now colorizeImage does not work the same way, as it doesnt' color only the caption TEXT but the caption BACKGROUND also ..!
For example if I set a black background and a white text :
$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->setBackgroundColor('black');
$im->colorizeImage('white',1.0);
I have a white background behind a white text, or a white box (the color of the text for the box) !
I tried different things, setBackgroundColor before or after colorizeImage, still the same... I've made lots of researches but found nothing else to color the caption and the background caption separately.
Anybody with an idea to help me ? Thx in advance :)
You want a transparent background. Then you will only color the foreground.
Use clutImage to apply the color. colorizeImage has issues with applying a slightly darker color when replacing black.
$im = new Imagick();
$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->setBackgroundColor('transparent');
$clut = new Imagick();
$clut->newImage(1, 1, new ImagickPixel('#ff0000'));
$txt->clutImage($clut);
$clut->destroy();
Not sure if this is what you want but this gives me white text on a black background:
$width = '600';
$height = '200';
$im = new Imagick();
$draw = new ImagickDraw();
$draw->setFont('arial.ttf');
$draw->setFontSize( 96 );
$fillcolor = new ImagickPixel( "white" );
$draw->setFillColor( $fillcolor );
$draw->setGravity( Imagick::GRAVITY_CENTER );
$bgcolor = new ImagickPixel( "black" );
$text = 'Rubblewebs';
$im->newImage($width, $height, $bgcolor );
$im->annotateImage($draw, 0, 0, 0, $text);
$im->setImageFormat("png");
$im->writeImage( 'text.png' );

Resources