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 bool lineComplete = false;
320 int startSel, endSel;
321 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.TextExtent(block.text + textPos, l, &tw, &th);
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.TextExtent(block.text + textPos, len, &tw, &th);
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.TextExtent(block.text + textPos, l, &tw, &th);
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);
461 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
466 if(block == endBlock && textPos >= endTextPos)
469 if(textPos >= block.textLen)
471 block = NextBlock(surface, block, null, RenderFlags { render = true });
477 bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
478 Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
481 int textPos = startTextPos;
482 Block block = startBlock;
483 bool lineComplete = false;
487 if(block == endBlock && textPos >= endTextPos)
496 x += block.window.size.w;
502 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
503 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
508 case HorizontalAlignment::left:
512 case HorizontalAlignment::right:
524 case bottom: dy = y + h - bh; break;
525 case top: dy = y; break;
526 case middle: dy = y + (h - bh) / 2; break;
529 if(block.bitmap || block.src)
531 if(pickX >= dx && pickY >= dy && pickX < dx + bw && pickY < dy + bh)
544 if(block == endBlock)
545 len = endTextPos - textPos;
547 len = block.textLen - textPos;
548 surface.TextExtent(block.text + textPos, len, &tw, &th);
549 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
551 if(pickX >= x && pickY >= y+h-th && pickX < x + tw && pickY < y+h)
555 // Have to properly compute this
564 surface.TextFont(block.font.font);
567 result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
569 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
574 if(block == endBlock && textPos >= endTextPos)
577 if(textPos >= block.textLen)
579 block = NextBlock(surface, block, null, RenderFlags { render = true });
587 void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
588 Block endBlock, int endTextPos, int left, int right)
590 int textPos = startTextPos;
591 Block block = startBlock;
592 bool lineComplete = false;
596 if(block == endBlock && textPos >= endTextPos)
605 Window parent = block.window.parent;
607 x + parent.scroll.x, y + parent.scroll.y,
608 block.window.size.w, block.window.size.h);
609 //block.window.visible = false;
610 x += block.window.size.w;
611 if(block.inputType == text)
620 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
621 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
626 case HorizontalAlignment::left:
630 case HorizontalAlignment::right:
642 case bottom: dy = y + h - bh; break;
643 case top: dy = y; break;
644 case middle: dy = y + (h - bh) / 2; break;
653 if(block == endBlock)
654 len = endTextPos - textPos;
656 len = block.textLen - textPos;
657 surface.TextExtent(block.text + textPos, len, &tw, &th);
658 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
666 surface.TextFont(block.font.font);
669 PositionTable(browser, surface, x, y, w, h, left, right, block);
671 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
676 if(block == endBlock && textPos >= endTextPos)
679 if(textPos >= block.textLen)
681 block = NextBlock(surface, block, null, RenderFlags { render = true });