4 /*static */Block NextBlockUp(Surface surface, Block block, int * centered, RenderFlags flags)
8 // Do we have younger siblings?
11 if(block.type == FONT || block.type == ANCHOR)
13 surface.TextFont(block.prevFont.font.font);
15 surface.SetForeground(block.prevFont.textColor);
23 // Getting out of a block
26 if(block.type == FONT || block.type == ANCHOR)
28 surface.TextFont(block.prevFont.font.font);
30 surface.SetForeground(block.prevFont.textColor);
32 else if(block.type == CENTER)
42 /*static */Block NextBlock(Surface surface, Block block, int * centered, uint flags)
44 // Do we have children?
45 if(block.subBlocks.first)
46 block = block.subBlocks.first;
49 block = NextBlockUp(surface, block, centered, flags);
54 int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nextBlock, int * nextTextPos, int * centered, int * w,
55 int maxW, int maxH, uint flags, int y, OldList leftObjects, OldList rightObjects, bool * changeLine, bool computeStartY, int sy, int sx)
59 bool lineComplete = false;
62 Block block = startBlock;
63 int textPos = startTextPos;
64 int width = 0, height = 0;
66 int centeredBefore = *centered;
72 *nextTextPos = textPos;
74 for(;!lineComplete && block;)
76 if(computeStartY && startTextPos == 0)
78 block.startX = x + sx;
79 block.startY = y + sy;
87 width += block.window.size.w;
88 height = Max(height, block.window.size.h);
94 int bw = block.pWidth ? (maxW * block.pWidth / 100) : block.w;
95 int bh = block.pHeight ? (maxH * block.pHeight / 100) : block.h;
97 if(block.halign == left || block.halign == right)
99 height = Max(height, bh);
103 if(leftObjects && rightObjects)
105 object = AlignedObject { w = bw, untilY = y + bh };
106 if(block.halign == left)
107 leftObjects.Add(object);
109 rightObjects.Add(object);
112 *nextBlock = NextBlockUp(surface, block, centered, flags);
122 if(x + width + bw > maxW && x > 0)
129 height = Max(height, bh);
136 char * text = block.text;
139 // TO FIX: THIS USED TO BE COMMENTED... PUT IT BACK FOR DOCUMENTOR
140 surface.TextExtent(" ", 1, null, &th);
141 height = Max(height, th);
144 for(; textPos<block.textLen && !lineComplete;)
148 char * nextSpace = strchr(text + textPos, ' ');
151 len = (nextSpace - (text + textPos)) + 1;
153 len = block.textLen - textPos;
155 surface.TextExtent(text + textPos, len, &w, &th);
157 if(x + width + w > maxW && x > 0)
166 height = Max(height, th);
170 *nextTextPos = textPos;
181 surface.TextFont(block.font.font);
186 surface.TextExtent(" ", 1, null, &th);
189 *nextBlock = NextBlock(surface, block, null, flags);
191 height = Max(height, th);
210 else if(block.halign == left || block.halign == right)
212 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
215 *nextBlock = NextBlockUp(surface, block, centered, flags);
221 if(leftObjects && rightObjects)
223 object = AlignedObject { w = block.w, untilY = y + block.h };
224 if(block.halign == left)
225 leftObjects.Add(object);
227 rightObjects.Add(object);
233 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
235 *nextBlock = NextBlockUp(surface, block, centered, flags);
244 if(lineComplete || !block)
247 if(textPos >= block.textLen)
250 block = NextBlock(surface, block, centered, flags);
251 // Break line after </center>
252 if(centeredBefore != *centered)
279 void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos, Block endBlock, int endTextPos, int left, int right)
281 int textPos = startTextPos;
282 Block block = startBlock;
283 bool lineComplete = false;
287 if(block == endBlock && textPos >= endTextPos)
296 x += block.window.size.w;
301 surface.SetForeground(block.textColor);
305 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
306 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
310 ColorAlpha fg = surface.GetForeground();
311 surface.SetForeground(white);
315 case HorizontalAlignment::left:
319 case HorizontalAlignment::right:
331 case bottom: dy = y + h - bh; break;
332 case top: dy = y; break;
333 case middle: dy = y + (h - bh) / 2; break;
338 if(bw == block.bitmap.width && bh == block.bitmap.height)
339 surface.Blit(block.bitmap, dx,dy,0,0,bw,bh);
341 surface.Stretch(block.bitmap, dx,dy,0,0,bw,bh,block.bitmap.width, block.bitmap.height);
343 else if(block.imageEntry && block.imageEntry.missing)
345 surface.Bevel(false, dx, dy, bw, bh);
346 if(browser.missing.bitmap)
347 surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0,
348 browser.missing.bitmap.width, browser.missing.bitmap.height);
350 surface.SetForeground(fg);
359 if(block == endBlock)
360 len = endTextPos - textPos;
362 len = block.textLen - textPos;
363 surface.TextExtent(block.text + textPos, len, &tw, &th);
364 surface.WriteText(x, y + h - th, block.text + textPos, len);
372 surface.TextFont(block.font.font);
373 surface.SetForeground(block.textColor);
376 RenderTable(browser, surface, x, y, w, h, left, right, block);
378 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
383 if(block == endBlock && textPos >= endTextPos)
386 if(textPos >= block.textLen)
388 block = NextBlock(surface, block, null, RenderFlags { render = true });
394 bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
395 Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
398 int textPos = startTextPos;
399 Block block = startBlock;
400 bool lineComplete = false;
404 if(block == endBlock && textPos >= endTextPos)
413 x += block.window.size.w;
419 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
420 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
425 case HorizontalAlignment::left:
429 case HorizontalAlignment::right:
441 case bottom: dy = y + h - bh; break;
442 case top: dy = y; break;
443 case middle: dy = y + (h - bh) / 2; break;
446 if(block.bitmap || block.src)
448 if(pickX >= dx && pickY >= dy && pickX < dx + bw && pickY < dy + bh)
461 if(block == endBlock)
462 len = endTextPos - textPos;
464 len = block.textLen - textPos;
465 surface.TextExtent(block.text + textPos, len, &tw, &th);
466 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
468 if(pickX >= x && pickY >= y+h-th && pickX < x + tw && pickY < y+h)
472 // Have to properly compute this
481 surface.TextFont(block.font.font);
484 result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
486 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
491 if(block == endBlock && textPos >= endTextPos)
494 if(textPos >= block.textLen)
496 block = NextBlock(surface, block, null, RenderFlags { render = true });
504 void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
505 Block endBlock, int endTextPos, int left, int right)
507 int textPos = startTextPos;
508 Block block = startBlock;
509 bool lineComplete = false;
513 if(block == endBlock && textPos >= endTextPos)
522 Window parent = block.window.parent;
524 x + parent.scroll.x, y + parent.scroll.y,
525 block.window.size.w, block.window.size.h);
526 //block.window.visible = false;
527 x += block.window.size.w;
528 if(block.inputType == text)
537 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
538 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
543 case HorizontalAlignment::left:
547 case HorizontalAlignment::right:
559 case bottom: dy = y + h - bh; break;
560 case top: dy = y; break;
561 case middle: dy = y + (h - bh) / 2; break;
570 if(block == endBlock)
571 len = endTextPos - textPos;
573 len = block.textLen - textPos;
574 surface.TextExtent(block.text + textPos, len, &tw, &th);
575 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
583 surface.TextFont(block.font.font);
586 PositionTable(browser, surface, x, y, w, h, left, right, block);
588 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
593 if(block == endBlock && textPos >= endTextPos)
596 if(textPos >= block.textLen)
598 block = NextBlock(surface, block, null, RenderFlags { render = true });