Click here to Skip to main content
15,885,546 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to avoid window swing when it zoom out from center point Pin
onlywjh17-Aug-10 20:58
onlywjh17-Aug-10 20:58 
AnswerRe: how to avoid window swing when it zoom out from center point Pin
onlywjh17-Aug-10 21:08
onlywjh17-Aug-10 21:08 
QuestionRotated text using Drawtext Pin
Mary Chennai11-Aug-10 8:15
Mary Chennai11-Aug-10 8:15 
AnswerRe: Rotated text using Drawtext Pin
Chris Losinger11-Aug-10 8:19
professionalChris Losinger11-Aug-10 8:19 
GeneralRe: Rotated text using Drawtext Pin
Mary Chennai11-Aug-10 8:38
Mary Chennai11-Aug-10 8:38 
GeneralRe: Rotated text using Drawtext Pin
Luc Pattyn11-Aug-10 8:48
sitebuilderLuc Pattyn11-Aug-10 8:48 
GeneralRe: Rotated text using Drawtext Pin
Maximilien11-Aug-10 9:00
Maximilien11-Aug-10 9:00 
GeneralRe: Rotated text using Drawtext Pin
CPallini11-Aug-10 22:20
mveCPallini11-Aug-10 22:20 
As suggested by Maximilien the computed rectangle is always aligned to screen coordinate space (i.e. rotation is not performed).
The following code (warning is a quick and dirty hack...)
#include <float.h>
#include <math.h>

//..

// draw the text
CSize TextSize = dc.GetTextExtent(str);
//CRect rect(0,0,TextSize.cx, TextSize.cy);

double x[4],y[4];
double alpha = ((double) Escapement) * atan(1.) * 4 / 1800;
x[0] = .0;
y[0] = .0;
x[1] = TextSize.cx * cos(alpha);
y[1] = -TextSize.cx * sin(alpha);
x[2] = TextSize.cx * cos(alpha) +TextSize.cy * sin(alpha);
y[2] = - TextSize.cx * sin(alpha) + TextSize.cy * cos(alpha);
x[3] = TextSize.cy * sin(alpha);
y[3] = TextSize.cy *cos(alpha);

double xoff=0.,yoff = 0.;
for (int i=0; i<4; i++)
{
  if ( xoff > x[i] ) xoff = x[i];
  if ( yoff > y[i] ) yoff = y[i];
}
for (int i=0; i<4; i++)
{
  x[i]-=xoff;
  y[i]-=yoff;
}
dc.MoveTo(x[0],y[0]);
dc.LineTo(x[1],y[1]);
dc.LineTo(x[2],y[2]);
dc.LineTo(x[3],y[3]);
dc.LineTo(x[0],y[0]);

double xmin = DBL_MAX;
double ymin = DBL_MAX;
double xmax = 0.;
double  ymax = 0.;
for (int i=0; i<4; i++)
{
  if (xmin > x[i]) xmin = x[i];
  if (ymin > y[i]) ymin = y[i];
  if (xmax < x[i]) xmax = x[i];
  if (ymax < y[i]) ymax = y[i];
}
CBrush *pOldBrush = (CBrush*)dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(xmin, ymin, xmax, ymax);
dc.SelectObject(pOldBrush);

CRect rect(xmin-xoff,ymin,xmax-xoff,ymax);

dc.DrawText(str, str.GetLength(), rect, DT_NOCLIP);
//...


Shows you:
  • The 'rotated text bounding rectangle'
  • The 'screen aligned rectangle' bounding the rotated one
  • The rotated text


Smile | :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

QuestionReading chunks of Data Pin
AbhiHcl11-Aug-10 3:05
AbhiHcl11-Aug-10 3:05 
AnswerRe: Reading chunks of Data Pin
CPallini11-Aug-10 3:27
mveCPallini11-Aug-10 3:27 
AnswerRe: Reading chunks of Data Pin
elchupathingy11-Aug-10 3:34
elchupathingy11-Aug-10 3:34 
GeneralRe: Reading chunks of Data Pin
AbhiHcl11-Aug-10 3:42
AbhiHcl11-Aug-10 3:42 
GeneralRe: Reading chunks of Data Pin
Cool_Dev11-Aug-10 4:47
Cool_Dev11-Aug-10 4:47 
AnswerRe: Reading chunks of Data Pin
bleedingfingers11-Aug-10 7:59
bleedingfingers11-Aug-10 7:59 
Questionwrong output ,error in my program Pin
0x808511-Aug-10 3:03
0x808511-Aug-10 3:03 
AnswerRe: wrong output ,error in my program Pin
mk1488211-Aug-10 3:19
mk1488211-Aug-10 3:19 
GeneralRe: wrong output ,error in my program Pin
0x808511-Aug-10 3:30
0x808511-Aug-10 3:30 
AnswerRe: wrong output ,error in my program Pin
Maximilien11-Aug-10 3:26
Maximilien11-Aug-10 3:26 
GeneralRe: wrong output ,error in my program Pin
0x808511-Aug-10 3:41
0x808511-Aug-10 3:41 
GeneralRe: wrong output ,error in my program Pin
mk1488211-Aug-10 4:24
mk1488211-Aug-10 4:24 
GeneralRe: wrong output ,error in my program Pin
0x808511-Aug-10 4:30
0x808511-Aug-10 4:30 
AnswerRe: wrong output ,error in my program Pin
elchupathingy11-Aug-10 3:41
elchupathingy11-Aug-10 3:41 
QuestionProblem with String Array Pin
T.RATHA KRISHNAN11-Aug-10 0:21
T.RATHA KRISHNAN11-Aug-10 0:21 
AnswerRe: Problem with String Array Pin
CPallini11-Aug-10 0:36
mveCPallini11-Aug-10 0:36 
GeneralRe: Problem with String Array Pin
T.RATHA KRISHNAN11-Aug-10 0:46
T.RATHA KRISHNAN11-Aug-10 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.