* convert shape coordinates to screen at the time of playing the picture

(fixes ticket #1367, stefano I thought you knew that I meant this in an
  earlier mail)
* move_pen_by() looked wrong in ServerPicture, have not tested though
* make sure the pen location is adjusted after stroke_line() and draw_string()
  in ServerPicture
* set_pen_location() does not need to update the Painter drawing state
* ServerWindow AS_LAYER_SET_PEN_SIZE needs to set the resulting pen size of
  the drawing state stack, not the one set on the current state
* ServerWindow AS_LAYER_GET_PEN_SIZE needs to return the current state's
  size, not the result of the stack
* small cleanups


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21855 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-08-08 18:36:23 +00:00
parent eb85607872
commit bbc424771b
2 changed files with 29 additions and 20 deletions

View File

@ -128,6 +128,7 @@ ShapePainter::Draw(ViewLayer *view, BRect frame, bool filled)
for(i = (ptCount - 1);i >= 0;i--) { for(i = (ptCount - 1);i >= 0;i--) {
ptList[i] = fPtStack.top(); ptList[i] = fPtStack.top();
fPtStack.pop(); fPtStack.pop();
view->ConvertToScreenForDrawing(&ptList[i]);
} }
view->Window()->GetDrawingEngine()->DrawShape(frame, opCount, opList, ptCount, ptList, view->Window()->GetDrawingEngine()->DrawShape(frame, opCount, opList, ptCount, ptList,
@ -173,16 +174,24 @@ nop()
static void static void
move_pen_by(ViewLayer *view, BPoint delta) move_pen_by(ViewLayer *view, BPoint delta)
{ {
view->CurrentState()->SetPenLocation(delta - view->CurrentState()->PenLocation()); // view->CurrentState()->SetPenLocation(delta - view->CurrentState()->PenLocation()); ?!?
view->CurrentState()->SetPenLocation(view->CurrentState()->PenLocation() + delta);
} }
static void static void
stroke_line(ViewLayer *view, BPoint start, BPoint end) stroke_line(ViewLayer *view, BPoint start, BPoint end)
{ {
BPoint penPos = end;
view->ConvertToScreenForDrawing(&start); view->ConvertToScreenForDrawing(&start);
view->ConvertToScreenForDrawing(&end); view->ConvertToScreenForDrawing(&end);
view->Window()->GetDrawingEngine()->StrokeLine(start, end); view->Window()->GetDrawingEngine()->StrokeLine(start, end);
view->CurrentState()->SetPenLocation(penPos);
// the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled
// by the view only
} }
@ -376,13 +385,20 @@ static void
draw_string(ViewLayer *view, const char *string, float deltaSpace, draw_string(ViewLayer *view, const char *string, float deltaSpace,
float deltaNonSpace) float deltaNonSpace)
{ {
// NOTE: the picture data was recorded with a "set pen location" command
// inserted before the "draw string" command, so we can use PenLocation()
BPoint location = view->CurrentState()->PenLocation(); BPoint location = view->CurrentState()->PenLocation();
escapement_delta delta = {deltaSpace, deltaNonSpace }; escapement_delta delta = {deltaSpace, deltaNonSpace };
view->ConvertToScreenForDrawing(&location); view->ConvertToScreenForDrawing(&location);
view->Window()->GetDrawingEngine()->DrawString(string, strlen(string), view->Window()->GetDrawingEngine()->DrawString(string, strlen(string),
location, &delta); location, &delta);
// TODO: Update pen location ?
view->ConvertFromScreenForDrawing(&location);
view->CurrentState()->SetPenLocation(location);
// the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled
// by the view only
} }
@ -482,12 +498,9 @@ static void
set_pen_location(ViewLayer *view, BPoint pt) set_pen_location(ViewLayer *view, BPoint pt)
{ {
view->CurrentState()->SetPenLocation(pt); view->CurrentState()->SetPenLocation(pt);
// the DrawingEngine/Painter does not need to be updated, since this
// TODO: faster version // effects only the view->screen coord conversion, which is handled
IntPoint p = view->ScrollingOffset(); // by the view only
p += IntPoint(view->CurrentState()->Origin());
view->Window()->GetDrawingEngine()->SetDrawState(
view->CurrentState(), p.x, p.y);
} }
@ -546,6 +559,9 @@ static void
set_scale(ViewLayer *view, float scale) set_scale(ViewLayer *view, float scale)
{ {
view->CurrentState()->SetScale(scale); view->CurrentState()->SetScale(scale);
// the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled
// by the view only
} }

View File

@ -1550,8 +1550,6 @@ ServerWindow::_DispatchViewMessage(int32 code,
link.Read<float>(&y); link.Read<float>(&y);
fCurrentLayer->CurrentState()->SetPenLocation(BPoint(x, y)); fCurrentLayer->CurrentState()->SetPenLocation(BPoint(x, y));
// TODO: is this necessary?
_UpdateDrawState(fCurrentLayer);
break; break;
} }
case AS_LAYER_GET_PEN_LOC: case AS_LAYER_GET_PEN_LOC:
@ -1570,15 +1568,16 @@ ServerWindow::_DispatchViewMessage(int32 code,
link.Read<float>(&penSize); link.Read<float>(&penSize);
fCurrentLayer->CurrentState()->SetPenSize(penSize); fCurrentLayer->CurrentState()->SetPenSize(penSize);
//_UpdateDrawState(fCurrentLayer); fWindowLayer->GetDrawingEngine()->SetPenSize(
fWindowLayer->GetDrawingEngine()->SetPenSize(penSize); fCurrentLayer->CurrentState()->PenSize());
break; break;
} }
case AS_LAYER_GET_PEN_SIZE: case AS_LAYER_GET_PEN_SIZE:
{ {
DTRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_SIZE: ViewLayer: %s\n", Title(), fCurrentLayer->Name())); DTRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_SIZE: ViewLayer: %s\n", Title(), fCurrentLayer->Name()));
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<float>(fCurrentLayer->CurrentState()->PenSize()); fLink.Attach<float>(
fCurrentLayer->CurrentState()->UnscaledPenSize());
fLink.Flush(); fLink.Flush();
break; break;
@ -1854,7 +1853,6 @@ ServerWindow::_DispatchViewMessage(int32 code,
link.Read(&c, sizeof(rgb_color)); link.Read(&c, sizeof(rgb_color));
fCurrentLayer->CurrentState()->SetHighColor(RGBColor(c)); fCurrentLayer->CurrentState()->SetHighColor(RGBColor(c));
// _UpdateDrawState(fCurrentLayer);
fWindowLayer->GetDrawingEngine()->SetHighColor(c); fWindowLayer->GetDrawingEngine()->SetHighColor(c);
break; break;
} }
@ -1866,7 +1864,6 @@ ServerWindow::_DispatchViewMessage(int32 code,
link.Read(&c, sizeof(rgb_color)); link.Read(&c, sizeof(rgb_color));
fCurrentLayer->CurrentState()->SetLowColor(RGBColor(c)); fCurrentLayer->CurrentState()->SetLowColor(RGBColor(c));
// _UpdateDrawState(fCurrentLayer);
fWindowLayer->GetDrawingEngine()->SetLowColor(c); fWindowLayer->GetDrawingEngine()->SetLowColor(c);
break; break;
} }
@ -1878,7 +1875,6 @@ ServerWindow::_DispatchViewMessage(int32 code,
link.Read(&pat, sizeof(pattern)); link.Read(&pat, sizeof(pattern));
fCurrentLayer->CurrentState()->SetPattern(Pattern(pat)); fCurrentLayer->CurrentState()->SetPattern(Pattern(pat));
// _UpdateDrawState(fCurrentLayer);
fWindowLayer->GetDrawingEngine()->SetPattern(pat); fWindowLayer->GetDrawingEngine()->SetPattern(pat);
break; break;
} }
@ -2575,14 +2571,11 @@ ServerWindow::_DispatchPictureMessage(int32 code, BPrivate::LinkReceiver &link)
&& link.Read(opList, opCount * sizeof(uint32)) >= B_OK && link.Read(opList, opCount * sizeof(uint32)) >= B_OK
&& link.Read(ptList, ptCount * sizeof(BPoint)) >= B_OK) { && link.Read(ptList, ptCount * sizeof(BPoint)) >= B_OK) {
// TODO: I'm not sure If I have to do this here (when the BPicture is
// recorded, or inside ServerPicture, when the picture is replayed.
// This might seem a bit weird, but under R5, the shapes // This might seem a bit weird, but under R5, the shapes
// are always offset by the current pen location // are always offset by the current pen location
BPoint penLocation = fCurrentLayer->CurrentState()->PenLocation(); BPoint penLocation = fCurrentLayer->CurrentState()->PenLocation();
for (int32 i = 0; i < ptCount; i++) { for (int32 i = 0; i < ptCount; i++) {
ptList[i] += penLocation; ptList[i] += penLocation;
fCurrentLayer->ConvertToScreenForDrawing(&ptList[i]);
} }
const bool fill = (code == AS_FILL_SHAPE); const bool fill = (code == AS_FILL_SHAPE);
picture->WriteDrawShape(opCount, opList, ptCount, ptList, fill); picture->WriteDrawShape(opCount, opList, ptCount, ptList, fill);