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.prevFont.font.font);
36 surface.SetForeground(block.prevFont.textColor);
44 // Getting out of a block
47 if(block.type == FONT || block.type == ANCHOR)
49 surface.TextFont(block.prevFont.font.font);
51 surface.SetForeground(block.prevFont.textColor);
53 else if(block.type == CENTER)
63 /*static */Block NextBlock(Surface surface, Block block, int * centered, uint flags)
65 // Do we have children?
66 if(block.subBlocks.first)
67 block = block.subBlocks.first;
70 block = NextBlockUp(surface, block, centered, flags);
75 int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nextBlock, int * nextTextPos, int * centered, int * w,
76 int maxW, int maxH, uint flags, int y, OldList leftObjects, OldList rightObjects, bool * changeLine, bool computeStartY, int sy, int sx)
80 bool lineComplete = false;
83 Block block = startBlock;
84 int textPos = startTextPos;
85 int width = 0, height = 0;
87 int centeredBefore = *centered;
93 *nextTextPos = textPos;
95 for(;!lineComplete && block;)
97 if(computeStartY && startTextPos == 0)
99 block.startX = x + sx;
100 block.startY = y + sy;
108 width += block.window.size.w;
109 height = Max(height, block.window.size.h);
115 int bw = block.pWidth ? (maxW * block.pWidth / 100) : block.w;
116 int bh = block.pHeight ? (maxH * block.pHeight / 100) : block.h;
118 if(block.halign == left || block.halign == right)
120 height = Max(height, bh);
124 if(leftObjects && rightObjects)
126 object = AlignedObject { w = bw, untilY = y + bh };
127 if(block.halign == left)
128 leftObjects.Add(object);
130 rightObjects.Add(object);
133 *nextBlock = NextBlockUp(surface, block, centered, flags);
143 if(x + width + bw > maxW && x > 0)
150 height = Max(height, bh);
157 char * text = block.text;
160 // TO FIX: THIS USED TO BE COMMENTED... PUT IT BACK FOR DOCUMENTOR
161 surface.TextExtent(" ", 1, null, &th);
162 height = Max(height, th);
165 for(; textPos<block.textLen && !lineComplete;)
169 char * nextSpace = strchr(text + textPos, ' ');
172 len = (nextSpace - (text + textPos)) + 1;
174 len = block.textLen - textPos;
176 surface.TextExtent(text + textPos, len, &w, &th);
178 if(x + width + w > maxW && x > 0)
187 height = Max(height, th);
191 *nextTextPos = textPos;
198 block.height += height;
203 surface.TextFont(block.font.font);
208 surface.TextExtent(" ", 1, null, &th);
211 *nextBlock = NextBlock(surface, block, null, flags);
213 height = Max(height, th);
232 else if(block.halign == left || block.halign == right)
234 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
237 *nextBlock = NextBlockUp(surface, block, centered, flags);
243 if(leftObjects && rightObjects)
245 object = AlignedObject { w = block.w, untilY = y + block.h };
246 if(block.halign == left)
247 leftObjects.Add(object);
249 rightObjects.Add(object);
255 ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
257 *nextBlock = NextBlockUp(surface, block, centered, flags);
266 if(lineComplete || !block)
269 if(textPos >= block.textLen)
272 block = NextBlock(surface, block, centered, flags);
273 if(block && block.type == TEXT)
275 // Break line after </center>
276 if(centeredBefore != *centered)
303 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)
305 int textPos = startTextPos;
306 Block block = startBlock;
307 bool lineComplete = false;
308 int startSel, endSel;
309 Block startSelBlock = null, endSelBlock = null;
310 if(browser.textBlock != browser.selBlock || browser.curPosition != browser.selPosition)
311 browser.NormalizeSelection(&startSelBlock, &startSel, &endSelBlock, &endSel);
315 Color fore = surface.foreground, back = surface.background;
316 if(block == endBlock && textPos >= endTextPos)
325 x += block.window.size.w;
330 surface.SetForeground(block.textColor);
334 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
335 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
339 ColorAlpha fg = surface.GetForeground();
340 surface.SetForeground(white);
344 case HorizontalAlignment::left:
348 case HorizontalAlignment::right:
360 case bottom: dy = y + h - bh; break;
361 case top: dy = y; break;
362 case middle: dy = y + (h - bh) / 2; break;
367 if(bw == block.bitmap.width && bh == block.bitmap.height)
368 surface.Blit(block.bitmap, dx,dy,0,0,bw,bh);
370 surface.Stretch(block.bitmap, dx,dy,0,0,bw,bh,block.bitmap.width, block.bitmap.height);
372 else if(block.imageEntry && block.imageEntry.missing)
374 surface.Bevel(false, dx, dy, bw, bh);
375 if(browser.missing.bitmap)
376 surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0,
377 browser.missing.bitmap.width, browser.missing.bitmap.height);
379 surface.SetForeground(fg);
386 int endPos = (block == endBlock) ? endTextPos : block.textLen;
387 int len = endPos - textPos;
389 if(startSelBlock && block == startSelBlock && startSel >= textPos && startSel <= textPos + len)
391 int l = startSel - textPos;
394 surface.TextExtent(block.text + textPos, l, &tw, &th);
395 surface.WriteText(x, y + h - th, block.text + textPos, l);
399 browser.isSelected = true;
403 if(endSelBlock && block == endSelBlock && endPos > textPos && endSel >= textPos && endSel < textPos + len)
404 len = endSel - textPos;
408 if(browser.isSelected)
410 surface.background = Color { 10, 36, 106 };
411 surface.foreground = white;
412 surface.textOpacity = true;
414 surface.TextExtent(block.text + textPos, len, &tw, &th);
415 surface.WriteText(x, y + h - th, block.text + textPos, len);
417 if(browser.isSelected)
419 surface.background = back;
420 surface.foreground = fore;
421 surface.textOpacity = false;
425 if(block == endSelBlock && textPos >= endSel)
426 browser.isSelected = false;
430 int l = endPos - textPos;
433 surface.TextExtent(block.text + textPos, l, &tw, &th);
434 surface.WriteText(x, y + h - th, block.text + textPos, l);
443 surface.TextFont(block.font.font);
444 surface.SetForeground(block.textColor);
447 RenderTable(browser, surface, x, y, w, h, left, right, block);
449 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
454 if(block == endBlock && textPos >= endTextPos)
457 if(textPos >= block.textLen)
459 block = NextBlock(surface, block, null, RenderFlags { render = true });
465 bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
466 Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
469 int textPos = startTextPos;
470 Block block = startBlock;
471 bool lineComplete = false;
475 if(block == endBlock && textPos >= endTextPos)
484 x += block.window.size.w;
490 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
491 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
496 case HorizontalAlignment::left:
500 case HorizontalAlignment::right:
512 case bottom: dy = y + h - bh; break;
513 case top: dy = y; break;
514 case middle: dy = y + (h - bh) / 2; break;
517 if(block.bitmap || block.src)
519 if(pickX >= dx && pickY >= dy && pickX < dx + bw && pickY < dy + bh)
532 if(block == endBlock)
533 len = endTextPos - textPos;
535 len = block.textLen - textPos;
536 surface.TextExtent(block.text + textPos, len, &tw, &th);
537 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
539 if(pickX >= x && pickY >= y+h-th && pickX < x + tw && pickY < y+h)
543 // Have to properly compute this
552 surface.TextFont(block.font.font);
555 result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
557 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
562 if(block == endBlock && textPos >= endTextPos)
565 if(textPos >= block.textLen)
567 block = NextBlock(surface, block, null, RenderFlags { render = true });
575 void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
576 Block endBlock, int endTextPos, int left, int right)
578 int textPos = startTextPos;
579 Block block = startBlock;
580 bool lineComplete = false;
584 if(block == endBlock && textPos >= endTextPos)
593 Window parent = block.window.parent;
595 x + parent.scroll.x, y + parent.scroll.y,
596 block.window.size.w, block.window.size.h);
597 //block.window.visible = false;
598 x += block.window.size.w;
599 if(block.inputType == text)
608 int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
609 int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
614 case HorizontalAlignment::left:
618 case HorizontalAlignment::right:
630 case bottom: dy = y + h - bh; break;
631 case top: dy = y; break;
632 case middle: dy = y + (h - bh) / 2; break;
641 if(block == endBlock)
642 len = endTextPos - textPos;
644 len = block.textLen - textPos;
645 surface.TextExtent(block.text + textPos, len, &tw, &th);
646 // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
654 surface.TextFont(block.font.font);
657 PositionTable(browser, surface, x, y, w, h, left, right, block);
659 block = NextBlockUp(surface, block, null, RenderFlags { render = true });
664 if(block == endBlock && textPos >= endTextPos)
667 if(textPos >= block.textLen)
669 block = NextBlock(surface, block, null, RenderFlags { render = true });