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;
321 if(browser.textBlock != browser.selBlock || browser.curPosition != browser.selPosition)
322 browser.NormalizeSelection(&startSelBlock, &startSel, &endSelBlock, &endSel);
326 Color fore = surface.foreground, back = surface.background;
327 if(block == endBlock && textPos >= endTextPos)
336 x += block.window.size.w;
341 surface.SetForeground(block.textColor);
345 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
346 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
350 ColorAlpha fg = surface.GetForeground();
351 surface.SetForeground(white);
355 case HorizontalAlignment::left:
359 case HorizontalAlignment::right:
371 case bottom: dy = y + h - bh; break;
372 case top: dy = y; break;
373 case middle: dy = y + (h - bh) / 2; break;
378 if(bw == block.bitmap.width && bh == block.bitmap.height)
379 surface.Blit(block.bitmap, dx,dy,0,0,bw,bh);
381 surface.Stretch(block.bitmap, dx,dy,0,0,bw,bh,block.bitmap.width, block.bitmap.height);
383 else if(block.imageEntry && block.imageEntry.missing)
385 surface.Bevel(false, dx, dy, bw, bh);
386 if(browser.missing.bitmap)
387 surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0,
388 browser.missing.bitmap.width, browser.missing.bitmap.height);
390 surface.SetForeground(fg);
397 int endPos = (block == endBlock) ? endTextPos : block.textLen;
398 int len = endPos - textPos;
400 if(startSelBlock && block == startSelBlock && startSel >= textPos && startSel <= textPos + len)
402 int l = startSel - textPos;
405 surface.TextExtent(block.text + textPos, l, &tw, &th);
406 surface.WriteText(x, y + h - th, block.text + textPos, l);
410 browser.isSelected = true;
414 if(endSelBlock && block == endSelBlock && endPos > textPos && endSel >= textPos && endSel < textPos + len)
415 len = endSel - textPos;
419 if(browser.isSelected)
421 surface.background = Color { 10, 36, 106 };
422 surface.foreground = white;
423 surface.textOpacity = true;
425 surface.TextExtent(block.text + textPos, len, &tw, &th);
426 surface.WriteText(x, y + h - th, block.text + textPos, len);
428 if(browser.isSelected)
430 surface.background = back;
431 surface.foreground = fore;
432 surface.textOpacity = false;
436 if(block == endSelBlock && textPos >= endSel)
437 browser.isSelected = false;
441 int l = endPos - textPos;
444 surface.TextExtent(block.text + textPos, l, &tw, &th);
445 surface.WriteText(x, y + h - th, block.text + textPos, l);
454 surface.TextFont(block.font.font);
455 surface.SetForeground(block.textColor);
458 RenderTable(browser, surface, x, y, w, h, left, right, block);
459 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
464 if(block == endBlock && textPos >= endTextPos)
467 if(textPos >= block.textLen)
469 block = NextBlock(surface, block, null, RenderFlags { render = true });
475 bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
476 Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
479 int textPos = startTextPos;
480 Block block = startBlock;
484 if(block == endBlock && textPos >= endTextPos)
493 x += block.window.size.w;
499 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
500 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
505 case HorizontalAlignment::left:
509 case HorizontalAlignment::right:
521 case bottom: dy = y + h - bh; break;
522 case top: dy = y; break;
523 case middle: dy = y + (h - bh) / 2; break;
526 if(block.bitmap || block.src)
528 if(pickX >= dx && pickY >= dy && pickX < dx + bw && pickY < dy + bh)
541 if(block == endBlock)
542 len = endTextPos - textPos;
544 len = block.textLen - textPos;
545 surface.TextExtent(block.text + textPos, len, &tw, &th);
546 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
548 if(pickX >= x && pickY >= y+h-th && pickX < x + tw && pickY < y+h)
552 // Have to properly compute this
561 surface.TextFont(block.font.font);
564 result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
565 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
570 if(block == endBlock && textPos >= endTextPos)
573 if(textPos >= block.textLen)
575 block = NextBlock(surface, block, null, RenderFlags { render = true });
583 void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
584 Block endBlock, int endTextPos, int left, int right)
586 int textPos = startTextPos;
587 Block block = startBlock;
591 if(block == endBlock && textPos >= endTextPos)
600 Window parent = block.window.parent;
602 x + parent.scroll.x, y + parent.scroll.y,
603 block.window.size.w, block.window.size.h);
604 //block.window.visible = false;
605 x += block.window.size.w;
611 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
612 //int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
617 case HorizontalAlignment::left:
621 case HorizontalAlignment::right:
634 case bottom: dy = y + h - bh; break;
635 case top: dy = y; break;
636 case middle: dy = y + (h - bh) / 2; break;
646 if(block == endBlock)
647 len = endTextPos - textPos;
649 len = block.textLen - textPos;
650 surface.TextExtent(block.text + textPos, len, &tw, &th);
651 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
659 surface.TextFont(block.font.font);
662 PositionTable(browser, surface, x, y, w, h, left, right, block);
663 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
668 if(block == endBlock && textPos >= endTextPos)
671 if(textPos >= block.textLen)
673 block = NextBlock(surface, block, null, RenderFlags { render = true });