Skip to content

Commit

Permalink
Add 4x2 block rendering (#20947)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 23, 2017
1 parent 056fc8e commit 8faa03f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 18 deletions.
22 changes: 16 additions & 6 deletions src/vs/editor/browser/viewParts/minimap/minimap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,36 @@ const enum RenderMinimap {
None = 0,
Small = 1,
Large = 2,
Blocks = 3,
SmallBlocks = 3,
LargeBlocks = 4,
}

function getMinimapLineHeight(renderMinimap: RenderMinimap): number {
if (renderMinimap === RenderMinimap.Large) {
return Constants.x2_CHAR_HEIGHT;
}
if (renderMinimap === RenderMinimap.LargeBlocks) {
return Constants.x2_CHAR_HEIGHT + 2;
}
if (renderMinimap === RenderMinimap.Small) {
return Constants.x1_CHAR_HEIGHT;
}
// RenderMinimap.Blocks
return 3;
// RenderMinimap.SmallBlocks
return Constants.x1_CHAR_HEIGHT + 1;
}

function getMinimapCharWidth(renderMinimap: RenderMinimap): number {
if (renderMinimap === RenderMinimap.Large) {
return Constants.x2_CHAR_WIDTH;
}
if (renderMinimap === RenderMinimap.LargeBlocks) {
return Constants.x2_CHAR_WIDTH;
}
if (renderMinimap === RenderMinimap.Small) {
return Constants.x1_CHAR_WIDTH;
}
// RenderMinimap.Blocks
return 1;
// RenderMinimap.SmallBlocks
return Constants.x1_CHAR_WIDTH;
}

class MinimapOptions {
Expand Down Expand Up @@ -749,8 +756,11 @@ export class Minimap extends ViewPart {
minimapCharRenderer.x2RenderChar(target, dx, dy, charCode, tokenColor, backgroundColor, useLighterFont);
} else if (renderMinimap === RenderMinimap.Small) {
minimapCharRenderer.x1RenderChar(target, dx, dy, charCode, tokenColor, backgroundColor, useLighterFont);
} else if (renderMinimap === RenderMinimap.LargeBlocks) {
minimapCharRenderer.x2BlockRenderChar(target, dx, dy, tokenColor, backgroundColor, useLighterFont);
} else {
minimapCharRenderer.blockRenderChar(target, dx, dy, tokenColor, backgroundColor, useLighterFont);
// RenderMinimap.SmallBlocks
minimapCharRenderer.x1BlockRenderChar(target, dx, dy, tokenColor, backgroundColor, useLighterFont);
}
dx += charWidth;
}
Expand Down
3 changes: 2 additions & 1 deletion src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2825,7 +2825,8 @@ export enum RenderMinimap {
None = 0,
Small = 1,
Large = 2,
Blocks = 3,
SmallBlocks = 3,
LargeBlocks = 4,
}

/**
Expand Down
74 changes: 73 additions & 1 deletion src/vs/editor/common/view/minimapCharRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,79 @@ export class MinimapCharRenderer {
}
}

public blockRenderChar(target: ImageData, dx: number, dy: number, color: RGBA, backgroundColor: RGBA, useLighterFont: boolean): void {
public x2BlockRenderChar(target: ImageData, dx: number, dy: number, color: RGBA, backgroundColor: RGBA, useLighterFont: boolean): void {
if (dx + Constants.x2_CHAR_WIDTH > target.width || dy + Constants.x2_CHAR_HEIGHT > target.height) {
console.warn('bad render request outside image data');
return;
}

const outWidth = target.width * Constants.RGBA_CHANNELS_CNT;

const c = 0.5;

const backgroundR = backgroundColor.r;
const backgroundG = backgroundColor.g;
const backgroundB = backgroundColor.b;

const deltaR = color.r - backgroundR;
const deltaG = color.g - backgroundG;
const deltaB = color.b - backgroundB;

const colorR = backgroundR + deltaR * c;;
const colorG = backgroundG + deltaG * c;
const colorB = backgroundB + deltaB * c;

const dest = target.data;
let destOffset = dy * outWidth + dx * Constants.RGBA_CHANNELS_CNT;
{
dest[destOffset + 0] = colorR;
dest[destOffset + 1] = colorG;
dest[destOffset + 2] = colorB;
}
{
dest[destOffset + 4] = colorR;
dest[destOffset + 5] = colorG;
dest[destOffset + 6] = colorB;
}

destOffset += outWidth;
{
dest[destOffset + 0] = colorR;
dest[destOffset + 1] = colorG;
dest[destOffset + 2] = colorB;
}
{
dest[destOffset + 4] = colorR;
dest[destOffset + 5] = colorG;
dest[destOffset + 6] = colorB;
}

destOffset += outWidth;
{
dest[destOffset + 0] = colorR;
dest[destOffset + 1] = colorG;
dest[destOffset + 2] = colorB;
}
{
dest[destOffset + 4] = colorR;
dest[destOffset + 5] = colorG;
dest[destOffset + 6] = colorB;
}

destOffset += outWidth;
{
dest[destOffset + 0] = colorR;
dest[destOffset + 1] = colorG;
dest[destOffset + 2] = colorB;
}
{
dest[destOffset + 4] = colorR;
dest[destOffset + 5] = colorG;
dest[destOffset + 6] = colorB;
}
}

public x1BlockRenderChar(target: ImageData, dx: number, dy: number, color: RGBA, backgroundColor: RGBA, useLighterFont: boolean): void {
if (dx + Constants.x1_CHAR_WIDTH > target.width || dy + Constants.x1_CHAR_HEIGHT > target.height) {
console.warn('bad render request outside image data');
return;
Expand Down
13 changes: 4 additions & 9 deletions src/vs/editor/common/viewLayout/editorLayoutProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,11 @@ export class EditorLayoutProvider {
contentWidth = remainingWidth;
} else {
let minimapCharWidth: number;
if (minimapRenderText) {
if (pixelRatio >= 2) {
renderMinimap = RenderMinimap.Large;
minimapCharWidth = 2 / pixelRatio;
} else {
renderMinimap = RenderMinimap.Small;
minimapCharWidth = 1 / pixelRatio;
}
if (pixelRatio >= 2) {
renderMinimap = minimapRenderText ? RenderMinimap.Large : RenderMinimap.LargeBlocks;
minimapCharWidth = 2 / pixelRatio;
} else {
renderMinimap = RenderMinimap.Blocks;
renderMinimap = minimapRenderText ? RenderMinimap.Small : RenderMinimap.SmallBlocks;
minimapCharWidth = 1 / pixelRatio;
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2596,7 +2596,8 @@ declare module monaco.editor {
None = 0,
Small = 1,
Large = 2,
Blocks = 3,
SmallBlocks = 3,
LargeBlocks = 4,
}

/**
Expand Down

0 comments on commit 8faa03f

Please sign in to comment.