4 Block GetNextBlock(Block block)
6 // Do we have children?
7 if(block.subBlocks.first)
8 block = block.subBlocks.first;
13 // Do we have younger siblings?
25 /*static */Block NextBlockUp(Surface surface, Block block, int * centered, RenderFlags flags)
29 // Do we have younger siblings?
32 if(block.type == FONT || block.type == ANCHOR)
34 surface.TextFont(block.parent.font.font);
36 surface.SetForeground(block.parent.textColor);
44 if(block.type == FONT || block.type == ANCHOR)
46 surface.TextFont(block.parent.font.font);
48 surface.SetForeground(block.parent.textColor);
53 // Getting out of a block
56 /*if(block.type == FONT || block.type == ANCHOR)
58 surface.TextFont(block.prevFont.font.font);
60 surface.SetForeground(block.prevFont.textColor);
62 else */if(block.type == CENTER)
72 /*static */Block NextBlock(Surface surface, Block block, int * centered, uint flags)
74 // Do we have children?
75 if(block.subBlocks.first)
76 block = block.subBlocks.first;
79 block = NextBlockUp(surface, block, centered, flags);
84 int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nextBlock, int * nextTextPos, int * centered, int * w,
85 int maxW, int maxH, uint flags, int y, OldList leftObjects, OldList rightObjects, bool * changeLine, bool computeStartY, int sy, int sx)
89 bool lineComplete = false;
92 Block block = startBlock;
93 int textPos = startTextPos;
94 int width = 0, height = 0;
96 int centeredBefore = *centered;
102 *nextTextPos = textPos;
104 for(;!lineComplete && block;)
106 if(computeStartY && startTextPos == 0)
108 block.startX = x + sx;
109 block.startY = y + sy;
117 width += block.window.size.w;
118 height = Max(height, Max(26, block.window.size.h));
124 int bw = block.pWidth ? (maxW * block.pWidth / 100) : block.w;
125 int bh = block.pHeight ? (maxH * block.pHeight / 100) : block.h;
127 if(block.halign == left || block.halign == right)
129 height = Max(height, bh);
133 if(leftObjects && rightObjects)
135 object = AlignedObject { w = bw, untilY = y + bh };
136 if(block.halign == left)
137 leftObjects.Add(object);
139 rightObjects.Add(object);
142 *nextBlock = NextBlockUp(surface, block, centered, flags);
152 if(x + width + bw > maxW && x > 0)
159 height = Max(height, bh);
166 char * text = block.text;
169 // TO FIX: THIS USED TO BE COMMENTED... PUT IT BACK FOR DOCUMENTOR
170 surface.TextExtent(" ", 1, null, &th);
171 height = Max(height, th);
173 for(; textPos<block.textLen && !lineComplete;)
177 char * nextSpace = strchr(text + textPos, ' ');
180 len = (nextSpace - (text + textPos)) + 1;
182 len = block.textLen - textPos;
184 surface.TextExtent(text + textPos, len, &w, &th);
186 if(x + width + w > maxW && x > 0)
195 height = Max(height, th);
199 *nextTextPos = textPos;
206 block.height += height;
211 surface.TextFont(block.font.font);
216 surface.TextExtent(" ", 1, null, &th);
219 *nextBlock = NextBlock(surface, block, null, flags);
221 height = Max(height, th);
240 else if(block.halign == left || block.halign == right)
242 Font font = surface.font;
243 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
247 *nextBlock = NextBlockUp(surface, block, centered, flags);
253 if(leftObjects && rightObjects)
255 object = AlignedObject { w = block.w, untilY = y + block.h };
256 if(block.halign == left)
257 leftObjects.Add(object);
259 rightObjects.Add(object);
265 Font font = surface.font;
266 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
269 *nextBlock = NextBlockUp(surface, block, centered, flags);
278 if(lineComplete || !block)
281 if(textPos >= block.textLen)
284 block = NextBlock(surface, block, centered, flags);
285 if(block && block.type == TEXT)
287 // Break line after </center>
288 if(centeredBefore != *centered)
315 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)
317 int textPos = startTextPos;
318 Block block = startBlock;
319 int startSel, endSel;
320 Block startSelBlock = null, endSelBlock = null;
322 if(browser.textBlock != browser.selBlock || browser.curPosition != browser.selPosition)
323 browser.NormalizeSelection(&startSelBlock, &startSel, &endSelBlock, &endSel);
327 Color fore = surface.foreground, back = surface.background;
328 if(block == endBlock && textPos >= endTextPos)
337 x += block.window.size.w;
342 surface.SetForeground(block.textColor);
346 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
347 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
351 ColorAlpha fg = surface.GetForeground();
352 surface.SetForeground(white);
356 case HorizontalAlignment::left:
360 case HorizontalAlignment::right:
372 case bottom: dy = y + h - bh; break;
373 case top: dy = y; break;
374 case middle: dy = y + (h - bh) / 2; break;
379 if(bw == block.bitmap.width && bh == block.bitmap.height)
380 surface.Blit(block.bitmap, dx,dy,0,0,bw,bh);
382 surface.Stretch(block.bitmap, dx,dy,0,0,bw,bh,block.bitmap.width, block.bitmap.height);
384 else if(block.imageEntry && block.imageEntry.missing)
386 surface.Bevel(false, dx, dy, bw, bh);
387 if(browser.missing.bitmap)
388 surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0,
389 browser.missing.bitmap.width, browser.missing.bitmap.height);
391 surface.SetForeground(fg);
398 int endPos = (block == endBlock) ? endTextPos : block.textLen;
399 int len = endPos - textPos;
401 if(startSelBlock && block == startSelBlock && startSel >= textPos && startSel <= textPos + len)
403 int l = startSel - textPos;
406 surface.TextExtent2(block.text + textPos, l, &tw, &th, prevGlyph, &prevGlyph, null);
407 surface.WriteText(x, y + h - th, block.text + textPos, l);
411 browser.isSelected = true;
415 if(endSelBlock && block == endSelBlock && endPos > textPos && endSel >= textPos && endSel < textPos + len)
416 len = endSel - textPos;
420 if(browser.isSelected)
422 surface.background = Color { 10, 36, 106 };
423 surface.foreground = white;
424 surface.textOpacity = true;
426 surface.TextExtent2(block.text + textPos, len, &tw, &th, prevGlyph, &prevGlyph, null);
427 surface.WriteText(x, y + h - th, block.text + textPos, len);
429 if(browser.isSelected)
431 surface.background = back;
432 surface.foreground = fore;
433 surface.textOpacity = false;
437 if(block == endSelBlock && textPos >= endSel)
438 browser.isSelected = false;
442 int l = endPos - textPos;
445 surface.TextExtent2(block.text + textPos, l, &tw, &th, prevGlyph, &prevGlyph, null);
446 surface.WriteText(x, y + h - th, block.text + textPos, l);
455 surface.TextFont(block.font.font);
456 surface.SetForeground(block.textColor);
459 RenderTable(browser, surface, x, y, w, h, left, right, block);
460 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
465 if(block == endBlock && textPos >= endTextPos)
468 if(textPos >= block.textLen)
470 block = NextBlock(surface, block, null, RenderFlags { render = true });
476 bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
477 Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
480 int textPos = startTextPos;
481 Block block = startBlock;
485 if(block == endBlock && textPos >= endTextPos)
494 x += block.window.size.w;
500 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
501 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
506 case HorizontalAlignment::left:
510 case HorizontalAlignment::right:
522 case bottom: dy = y + h - bh; break;
523 case top: dy = y; break;
524 case middle: dy = y + (h - bh) / 2; break;
527 if(block.bitmap || block.src)
529 if(pickX >= dx && pickY >= dy && pickX < dx + bw && pickY < dy + bh)
542 if(block == endBlock)
543 len = endTextPos - textPos;
545 len = block.textLen - textPos;
546 surface.TextExtent(block.text + textPos, len, &tw, &th);
547 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
549 if(block.text[0] == ' ' && block.text[1] == 0) pickX += tw; else
550 if(pickX >= x && pickY >= y+h-th && pickX < x + tw + 2 && pickY < y+h)
554 // Have to properly compute this
563 surface.TextFont(block.font.font);
566 result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
567 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
572 if(block == endBlock && textPos >= endTextPos)
575 if(textPos >= block.textLen)
577 block = NextBlock(surface, block, null, RenderFlags { render = true });
585 void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
586 Block endBlock, int endTextPos, int left, int right)
588 int textPos = startTextPos;
589 Block block = startBlock;
593 if(block == endBlock && textPos >= endTextPos)
602 Window parent = block.window.parent;
604 x + parent.scroll.x, y + parent.scroll.y,
605 block.window.size.w, block.window.size.h);
606 //block.window.visible = false;
607 x += block.window.size.w;
613 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
614 //int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
619 case HorizontalAlignment::left:
623 case HorizontalAlignment::right:
636 case bottom: dy = y + h - bh; break;
637 case top: dy = y; break;
638 case middle: dy = y + (h - bh) / 2; break;
648 if(block == endBlock)
649 len = endTextPos - textPos;
651 len = block.textLen - textPos;
652 surface.TextExtent(block.text + textPos, len, &tw, &th);
653 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
661 surface.TextFont(block.font.font);
664 PositionTable(browser, surface, x, y, w, h, left, right, block);
665 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
670 if(block == endBlock && textPos >= endTextPos)
673 if(textPos >= block.textLen)
675 block = NextBlock(surface, block, null, RenderFlags { render = true });