How to change cursorline color when changing to command mode - neovim

This code changes the cursorline color when in insert, normal and replace mode at least but doesn't really work in visual mode and doesn't work at all in command mode. Whats wrong?
function Pain()
local colors = {
bg = "#202328",
fg = "#bbc2cf",
yellow = "#ECBE7B",
cyan = "#008080",
darkblue = "#081633",
green = "#3d5122",
orange = "#FF8800",
violet = "#a9a1e1",
magenta = "#c678dd",
blue = "#51afef",
red = "#6f3328",
}
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.yellow,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
tr= colors.red,
}
local color = mode_color[vim.api.nvim_get_mode().mode]
if color == nil then
color = "NONE"
end
print(vim.api.nvim_get_mode().mode)
vim.api.nvim_command("hi! CursorLine guifg=NONE guibg=".. color)
end
vim.api.nvim_command([[autocmd ModeChanged * lua Pain()]])

Related

WebGL Texture pixel unexpected color in PNG [duplicate]

This question already has an answer here:
Fragment Shader: wrong color value from texture
(1 answer)
Closed 6 months ago.
I am trying to load a texture into WebGl and read a pixel color from it (to eventually use in a shader). When I read the pixel color at position 70,70 in python, I get (255,0,0,255) which is what I expected. But when I read it in WebGL, I get (255,38,0,255). What am I missing here?
Image: https://i.imgur.com/jGA12NE.png
JSFiddle: https://jsfiddle.net/6u7h0sj1/3/
Python code:
import requests
from io import BytesIO
response = requests.get('https://i.imgur.com/jGA12NE.png')
im = Image.open(BytesIO(response.content))
pixels=im.load()
print(pixels[70,70])
Javascript code to read pixel of texture:
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
const gl= canvas.getContext("webgl",{"antialias":true});
function loadTexture(){
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
const level = 0;
const internalFormat = gl.RGBA;
const width = 1;
const height = 1;
const border = 0;
const srcFormat = gl.RGBA;
const srcType = gl.UNSIGNED_BYTE;
const pixel = new Uint8Array([0, 0, 255, 255]); // opaque blue
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
width, height, border, srcFormat, srcType,
pixel);
const image = new Image();
image.crossOrigin = ""; // or "anonymous", will be interpreted the same
image.onload = () => {
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
srcFormat, srcType, image);
let width=1;
let height=1;
let x=70;
let y=70;
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
var pixels = new Uint8Array(width * height * 4);
gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
document.getElementById("test").textContent=pixels;
}
};
image.src = 'https://i.imgur.com/jGA12NE.png';
}
loadTexture();
Found this helpful answer:
Fragment Shader: wrong color value from texture
Solved by adding the following line before loading the texture:
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, false);

Generate custom color shades from parent color in flutter

I needs to find a better approach to generate shade colors from a given custom color for theming purposes. So far I found a way to do this by reducing opacity of the given color as below. so I can accent Color color and faded color of given color to this function.
import 'package:flutter/material.dart';
class AppColors {
Color accentColor;
Color fadedColor;
AppColors(this.accentColor, this.fadedColor);
}
AppColors getAppColors(String color) {
int budgetAccentcolor = int.parse('0xff' + color);
int budgetFadedColor = int.parse('0x26' + color);
return AppColors(Color(budgetAccentcolor), Color(budgetFadedColor));
}
But because of I'm reducing opacity of the color It shows what's going under the widgets like when using SliverAppBar.
Is there anyway to get the faded value of a Hex color?
Finally found a way from here.
Color lighten(Color color, [double amount = 0.49]) {
assert(amount >= 0 && amount <= 1);
final hsl = HSLColor.fromColor(color);
final hslLight = hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));
return hslLight.toColor();
}
Color hexToColor(String code) {
return Color(int.parse(code.substring(0, 6), radix: 16) + 0xFF000000);
}
And Im calling this fucntion like this.
backgroundColor: lighten(hexToColor("f98b5")),

Scalajs: adding a border to a canvas

I've been trying to add a border to a canvas in Scalajs. I mean add a border to the Canvas itself not add a border to an object on the canvas. I am hence looking for methods on the Canvas itself not on the Graphics context from the canvas. So I have the following code which paints a brown square in the top right of the canvas:
val can: html.Canvas = document.createElement("canvas").asInstanceOf[html.Canvas]
document.body.appendChild(can)
val width = window.innerWidth -20
val height = (window.innerHeight - 80)
can.width = width.toInt
can.height = height.toInt
//val dec = new raw.CSSStyleDeclaration()
val gc = can.getContext("2d").asInstanceOf[raw.CanvasRenderingContext2D]
//display.can.setProperty("borderColor", Colour.black.hexStr)
gc.fillStyle = "#AA5500"
gc.fillRect(0, 0, 200, 200)
//dec.borderWidth = "2"
//display.can.style = dec
Looking at the documentation it seems I need to create a CSSStyleDeclaration. But as soon as I uncomment the val dec = ... line, I get a TypeError: Illegal constructor, when I run it in the Web console. Chrome's console points to the following javascript line as the problem:
new $g["CSSStyleDeclaration"]();
Edit: this works, but I'd prefer to use the proper ScalaJs methods rather resorting to dynamic:
can.asInstanceOf[scalajs.js.Dynamic].style = "border:2px solid black;"
This shows how to do the stroke with strokeRect. The canvas.strokeRect splits the stroke so that it falls partially outside and partially inside. There's an adjustment to keep all the stroke inside the canvas. You should be able to convert this to ScalaJs.
var can = document.createElement("canvas");
document.body.appendChild(can);
var width = window.innerWidth -20;
var height = (window.innerHeight - 80);
can.width = width;
can.height = height;
//val dec = new raw.CSSStyleDeclaration()
var gc = can.getContext("2d");
//display.can.setProperty("borderColor", Colour.black.hexStr)
gc.fillStyle = "#AA5500";
gc.fillRect(0, 0, 200, 200);
//dec.borderWidth = "2"
//display.can.style = dec
gc.strokeStyle = "#000000";
var strokeSize = 10;
var halfStroke = strokeSize / 2;
gc.lineWidth = strokeSize;
gc.strokeRect(0 + halfStroke,0 + halfStroke,width-strokeSize,height-strokeSize);

event processing in dojo surface

I have a surface where i draw some kind of dynamic image based on the data from my backend, on click of a certain area, i want different data to be published. but my following code always takes last data drawn to publish.
function renderICD() {
var totalx=1200;
var totaly=1000;
var xOffset = 150;
var yOffset = 20;
surface = dojox.gfx.createSurface("icdTab",totalx+2,totaly+2);
var grid = surface.createGroup();
var step = 1;
var xyHolder = {};
var group = grid.createGroup();
for(var ii=0;ii<2;ii++)
{
var x = (step-1) * (75+85);
step++;
var group = grid.createGroup();
group.createRect({x:xOffset+x+33, y:yOffset+20+90, width: 10, height: 10}).setFill([255, 255, 255, 0.9])
.setStroke({color:'black' , width:2});
dojo.connect(group.getEventSource(),"onclick",function(e) {
var internal = ii;
alert("publishing "+internal);
//shape was clicked, now do something!
});
grid.createText({x:xOffset+x+33, y:yOffset+20+80, text:ii,align:"middle"})
.setFill('red')
.setFont({size: '10px',weight: "bold"});
}
}
As i understand, only 1 instance of function written to handle event is present, but what i am trying to handle is 2 different events.
How can i achieve this?
Snapshot of surface with 2 rects, when i click on both rects, i get '2' in my alert.
JavaScript has functional scope, not block scope, so you only have one ii variable, which is always equal to "2" by the time you click on a rect. There are many ways to fix this, example below :
function renderICD() {
var totalx=1200;
var totaly=1000;
var xOffset = 150;
var yOffset = 20;
surface = dojox.gfx.createSurface("icdTab",totalx+2,totaly+2);
var grid = surface.createGroup();
var step = 1;
var xyHolder = {};
var group = grid.createGroup();
dojo.forEach([0,1], function(item, ii) {
var x = (step-1) * (75+85);
step++;
var group = grid.createGroup();
group.createRect({x:xOffset+x+33, y:yOffset+20+90, width: 10, height: 10}).setFill([255, 255, 255, 0.9])
.setStroke({color:'black' , width:2});
dojo.connect(group.getEventSource(),"onclick",function(e) {
var internal = ii;
alert("publishing "+internal);
//shape was clicked, now do something!
});
grid.createText({x:xOffset+x+33, y:yOffset+20+80, text:ii,align:"middle"})
.setFill('red')
.setFont({size: '10px',weight: "bold"});
});
}

Background color for TabControl?

I'm working on a browser that's running on Geckofx, and well I can't find a way to change the color of the TabControl
I don't want to change the tab page, I want to change the container.
Here's what I mean:
This is what i'm trying to do:
And this is where i'm at:
I'm already using this for the tabs
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
{
TabPage CurrentTab = tabControl.TabPages[e.Index];
Rectangle ItemRect = tabControl.GetTabRect(e.Index);
SolidBrush FillBrush = new SolidBrush(Color.Red);
SolidBrush FBG = new SolidBrush(Color.Black);
SolidBrush TextBrush = new SolidBrush(Color.Green);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
{
FillBrush.Color = Color.Black;
TextBrush.Color = Color.Green;
ItemRect.Inflate(0, 0);
}
if (tabControl.Alignment == TabAlignment.Left || tabControl.Alignment == TabAlignment.Right)
{
float RotateAngle = 90;
if (tabControl.Alignment == TabAlignment.Left)
RotateAngle = 270;
PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 3), ItemRect.Top + (ItemRect.Height / 5));
e.Graphics.TranslateTransform(cp.X, cp.Y);
e.Graphics.RotateTransform(RotateAngle);
ItemRect = new Rectangle(-(ItemRect.Height / 3), -(ItemRect.Width / 3), ItemRect.Height, ItemRect.Width);
}
e.Graphics.FillRectangle(FillBrush, ItemRect);
e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);
e.Graphics.ResetTransform();
FillBrush.Dispose();
TextBrush.Dispose();
}
}
I just have no idea how to change the color of the TabControl
I've looked over online everywhere and the examples either made 0 sense whatsoever or did not work.
I know it's possible from the example i've seen
Can anyone help?
TabControl have the propertie BackColor, from Control. Maybe if nothing work, try to set the DefaultBackColor to the color you need for your TabControl?
Look at this : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.defaultbackcolor.aspx