Libgdx draws a smooth ring on the fly - libgdx

I need to draw a ring on the fly. However, in practice, I use ShapeRenderer to draw such a small ring whose radius is 32px and border width is 1px, its result is ugly. Compared with browser render result, I give screenshots.
css:
libgdx:
How to draw ring on the fly like using CSS. (Prepare ring textures with vary sizes, but it is against my original intend).
How to draw ring with a specific line width like using HTML5 canvas.
.numberCircle {
border-radius: 50%;
/* behavior: url(PIE.htc); remove if you don't care about IE8 */
width: 16px;
height: 16px;
/*padding: 8px;*/
line-height: 16px;
background: #fff;
border: 1px solid #666;
color: #666;
text-align: center;
font: 8px Arial, sans-serif;
}
<div class="numberCircle">0</div>
<div class="numberCircle">1</div>

What you probably want is to enable antialiasing, it's enabled when you initialize your application. Taken from this answer:
Enable anti-alising in the configuration:
For Desktop:
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.samples = 2;
new LwjglApplication(new MyGdxGame(Helper.arrayList(arg)), config);
For Android:
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.numSamples = 2;
initialize(new MyGdxGame(null), config);
You might also need to add these lines inside of the application:
Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH);
Gdx.gl.glEnable(GL10.GL_POINT_SMOOTH);

Related

Why does the 'same' code looks different in the same browser with the same size, where one deployment is on localhost and the other remote

I have some Material-UI Table where I styled the headers and tables.
When I was running the app locally with yarn start I have this look:
And this is how it looks like on the remote system:
It's not like the font-size is different, but also it's not centred.
I am not really sure what's the reason for it to look different on the same browser, on the same system just in a different tab.
Here are the relevant code changes I did apply:
const StyledTableRow = styled(TableRow)(({ theme }) => ({
'&:nth-of-type(odd)': {
backgroundColor: theme.palette.action.hover,
},
// hide last border
'&:last-child td, &:last-child th': {
border: 0,
},
}));
const StyledAvatar = styled(Avatar)`
box-shadow: 0px 1px 3px #777;
`;
const NoTableCellPadding = styled(TableCell)`
font-size: 0.75rem;
font-family: Roboto;
text-align: center;
&.MuiTableCell-head {
background: linear-gradient(#ddd, #fff 40%, #ddd);
border-right: 1px solid #ccc;
}
&.MuiTableCell-head:last-child th' {
border-right: none;
}
`;
So now I am wondering what could be the reasons, where to look for that the changes don't seem to be applied. Any hints?
In the end it turned out to be this:
const NoTableCellPadding = styled(TableCell)`
font-size: 0.75rem;
font-family: Roboto;
text-align: center;
...
It needs to be like this:
const NoTableCellPadding = styled(TableCell)`
& {
font-size: 0.75rem;
font-family: Roboto;
text-align: center;
}
...
Which doesn't explain however why I didn't see this locally, but it's quite possible that this is related to the way how the hot reload feature of the yarn start works and how it adds the style information. Using styled results in optimized CSS after it has been compiled for a release build.
Henty gave a good comment however, to check for the differences. It was however not quite obvious why they were different until I saw masses of <style> tags in the inspector.
So thanks Henty!

Remove input[range] inner line

I would like to remove the inner line of the range-input (HTML5 Video Control). Is there any way?
Have a Look!
If this is simply an HTML <video> element then you are going to be rather limited as to how you can handle styling it. The appearance of these elements will differ from browser to browser as seen below :
Firefox
Google Chrome
Internet Explorer
Edge
These styles are extremely difficult and sometimes impossible to override (especially in any kind of consistent fashion) as they rely on styles that are browser-specific as seen below:
audio::-webkit-media-controls-timeline, video::-webkit-media-controls-timeline {
-webkit-appearance: media-slider;
display: flex;
height: 8px;
background-color: transparent;
min-width: 25px;
color: inherit;
flex: 1 1 auto;
margin: 0px 15px 0px 0px;
padding: 0px;
border: initial;
}
or specifically for the range section :
input[type="range" i] {
color: rgb(196, 196, 196);
}
You could try to use a style that would explicitly override it, but your success may vary :
input[type="range" i] {
/* Attempt to hide this */
color: transparent!important;
}
If you are looking for something like that, you would probably be better off using a Javascript-based like JPlayer or MediaElement.js

Font size discrepancy between computed font size and CSS defined font size?

I have a certain HTML element: a textarea with some CSS
<textarea id="mytextarea"
class="absoluteelement inputtable paddable"
style="resize:none;top:70.68187%;left:4.705374%;width:90%;height:11.5%;Background-color:transparent;">
</textarea>
And the css:
#mytextarea {
font-size: 10.0px;
font-color: #FF000000;
font-family: arial;
text-align: left;
}
input,select,textarea {
border: none;
background: transparent;
}
.paddable {
padding-left: 5px;
padding-right: 5px;
box-sizing: border-box;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /*FF, IE8*/
}
textarea {
resize: none;
overflow:hidden;
}
.absoluteelement {
position: absolute;
}
Now my problem is this. When I try
var textarea = document.getElementById("mytextarea");
var style = window.getComputedStyle(textarea);
console.log(style.fontSize);
The console logs 9.85012722015381px. Yet when I inspect the textarea with Chrome's developers panel (style tab), it shows
#mytextarea {
font-size: 10.0px;
font-color: #FF000000;
font-family: arial;
text-align: left;
}
and in the computed panel, it shows, like the console output:
> font-size: 9.85012722015381px;
Why is there a discrepancy between the two values? I clearly stated that the font size is 10.0px, and I can't find the number 9.85...px anywhere in my css.
UPDATE:
This does only seem to happen in Chrome; Firefox displays and logs a computed font size of 10.0px
UPDATE 2:
It seems the fontSize changes when zooming in or out on Chrome.
As far as I know, it's really the Chrome-specific issue.
First of all, if you set the font size in pixels, you should use only the round numbers, i.e. font-size: 10px; and not font-size: 10.0px; The floating-point numbers are meaningless for pixels and only put browser down.
However, you should't worry because all the numbers you provide are actually mapped to 10px font size. If you need to recognize the actual font size in your code in order to do something with it, you can round the number:
var myTextArea = document.getElementById("mytextarea");
var fontSize = window.getComputedStyle(myTextArea).fontSize.replace("px","");
var fontSize = Math.round(fontSize);

Why does my button background get cut off in Firefox but not Google Chrome?

I have the following CSS:
html.darkBlue button {
border-color: #cccccc;
color: #222222;
background: linear-gradient(#fafafc, #ededf0 50%, #e3e3e5 50%, #e8e8eb);
}
.question-marking-buttons button {
padding: 0.4rem;
height: 1.4rem;
line-height: 1.4rem;
margin-right: 0.5rem;
float: left;
width: 4rem;
}
Here's my HTML:
<button>Mark</button>
In Google Chrome the button background extends from the top of the button to the bottom like this:
xxxxxxxxx
x x
x Mark x
x x
xxxxxxxxx
In Firefox it looks like this:
xxxxxxxxx
x x
x Mark x
xxxxxxxxx
Can someone give me advice on why the background is getting cut off in Firefox but not Chrome?
EDIT:
OK a few reasons
First issue, is problem with height, width, and line-height.
Second issue, is that the reason buttons and divs are different sizes in Firefox and Chrome, is only because of the text size. Firefox makes slightly bigger text size.
For example, if you have a text size of 15px, well Firefox makes a larger 15px than Chrome does.
The way I fixed this on my own website, is by using cufon for the text. Since cufon is an external font, it displays the exact same width on Firefox, Chrome, and every other browser. This solved my menubar width and button width cross-browser problems.
You should also use px or em instead of rem, just a tip.
NOTE 1: I hosted the necessary cufon files on yourjavascript.com for this example. However, you should either download those files and host on your own website, or create the files yourself from the cufon website, and host the files on your own site.
NOTE 2: To get the font file to upload to cufon to create the cufon fonts file, just go into C:\Windows\Fonts\ and find the font you want to use (i.e. Arial) and copy it to your desktop. Then upload that font file onto the cufon website for hosting. You can also download font files from google fonts or other sites, if you want different fonts to use with cufon.
SUMMARY:
Problem 1: line-height extends height
Problem 2: padding is wrong
Problem 3: firefox makes different size text. Use cufon to circumvent issue
Problem 4: needs padding-before hack
Problem 5: needs box-sizing hack. This prevents padding from being added to the width.
Problem 6: need to set css to button specifically, for good measure.
See my finished fix on jsbin:
http://jsbin.com/AxiCiNA/3
The code (same thing from the jsbin I created):
page.html
<html>
<head>
<script src="http://yourjavascript.com/319153210071/cufon-yui.js"></script>
<script type="text/javascript" src="http://yourjavascript.com/330149971117/thearialcufonfile.js"></script>
</head>
<body>
<button id='one'>Mark</button>
<button id='two'>Mark</button>
</body>
</html>
style.css
#one {
border-color: #cccccc;
color: #222222;
background: linear-gradient(#fafafc, #ededf0 50%, #e3e3e5 50%, #e8e8eb);
}
button#two {
padding: 1px 8px;
margin: 0;
margin-right: 9px;
float: left;
font: 15px 'Times New Roman, Serif';
height: 25px;
width: 50px;
line-height: 10px;
/* box-sizing hack for chrome */
-webkit-box-sizing: border-box;
/* box-sizing hack for firefox */
-moz-box-sizing: border-box;
/* box-sizing hack for opera */
box-sizing: border-box;
/* padding-before hack for chrome */
-webkit-padding-before: 1px;
-webkit-padding-after: 0;
-webkit-padding-start: 1px;
-webkit-padding-end: 0;
/* padding-before hack for firefox */
-moz-padding-before: 0px;
-moz-padding-after: 0;
-moz-padding-start: 1px;
-moz-padding-end: 0;
/* padding-before hack for opera */
padding-before: 1px;
padding-after: 0;
padding-start: 1px;
padding-end: 0;
}
script.js
Cufon.replace('#two', { fontFamily: 'Arial' });
It's because of those two lines :
padding: 0.4rem;
height: 1.4rem;
That's too much padding for that height.
Try this
padding: 0;
height: 1.5rem;

HTML5 Canvas color differentiation

I'm trying to draw a popup using HTML5 canvas.
The popup is composed of a canvas that draws an arrow and a div below:
As you can clearly see, the color of the arrow is darker than the div's background-color.
The code is injected into every tab of the browser and the popup is shown upon selection of text.
Here's the drawing code:
var ctx = $('#popupCanvas')[0].getContext("2d");
ctx.moveTo(10, 0);
ctx.lineTo(0, 10);
ctx.lineTo(20, 10);
ctx.fillStyle = "rgba(50,50,50,0.9)";
ctx.fill();
and the CSS of the div is :
#popupMenu
{
line-height: 0px;
display:block;
background-color:rgba(50,50,50,0.9);
color:#ddd;
-webkit-box-shadow: 2px 2px 5px #555;
-webkit-border-radius:5px;
font-family: Century Gothic, sans-serif;
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size:0px;
padding:5px;
width:345px;
}
As you can see, the colors are the same and yet they are rendered differently.
What am I doing wrong?
Why are there any differences? I'm using Webkit under chrome 15.
Edit1
I forgot to mention, the popup is running as injected javascript\css.
Adding the HTML source code:
<div id='popupContainer'>
<canvas id='popupCanvas' width='20' height='10'/>
<div id='popupMenu'>
</div>
</div>
and the full CSS:
#popupCanvas
{
position:relative;
margin:0px;
padding:0px;
}
#popupContainer
{
position:absolute;
z-index: 999999;
direction:ltr;
text-align:center;
}
#popupMenu
{
line-height: 0px;
display:block;
background-color:rgba(50,50,50,0.9);
color:#ddd;
-webkit-box-shadow: 2px 2px 5px #555;
-webkit-border-radius:5px;
font-family: Century Gothic, sans-serif;
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size:0px;
padding:5px;
width:345px;
}
Edit2
Here's my entire code upon user selection :
this.onTextSelected = function (selText) {
selectedText = selText;
// check if we have value
var selection = window.getSelection();
var node = document.elementFromPoint(currentMousePos.x, currentMousePos.y);
if (node.value) {
rect = getTextBoundingRect(node, $(node).caret().start, $(node).caret().end);
}
else
rect = selection.getRangeAt(0).getBoundingClientRect();
var bottom = rect.bottom + document.body.scrollTop;
var left = rect.left + document.body.scrollLeft
$("#popupContainer").css('top', bottom);
// Div exceeds left side
if (left - $("#popupContainer").outerWidth() / 2 < 0) {
$("#popupContainer").css('left', left);
// TODO: set the arrow to be left
}
// Div exceeds right side
else if (left + $("#popupContainer").outerWidth() / 2 > $(window).width()) {
$("#popupContainer").css('left', left + rect.width - $("#popupContainer").outerWidth());
// TODO: set the arrow to be right
}
else {
$("#popupContainer").css('left', left + rect.width / 2 - $("#popupContainer").outerWidth() / 2);
}
$("#popupContainer").show();
var ctx = $('#popupCanvas')[0].getContext("2d");
ctx.moveTo(10, 0);
ctx.lineTo(0, 10);
ctx.lineTo(20, 10);
ctx.fillStyle = "rgba(50,50,50,0.9)";
ctx.fill();
};
I'd suggest trying to define it in something other than rgba as a potential fix, although it is quite strange.
On another point, i'd consider using a pseudo element (see here for a great article) for the arrow, it seems a bit unnecessary to use a whole canvas element for such a detail. Whilst support might not be fantastic/consistent, neither is that for canvas so I'd say it's likely a good swap.
I'd believe this is because pop-up background shines through canvas (which has alpha 0.9). On the othe hand, pop-up itself is drawn on light background.
Try modify alpha values to see if this is the cause of the problem.
I'm not able to reproduce this issue. Can you provide full code?
I added a fiddle below with a slighlty larger triangle and used un-vendor prefixed versions of border-radius and box shadow so that it works across IE9, Opera and Mozilla as well as webkit browser.
I also added a -5px margin to the bottom div to cause an overlap.
http://jsfiddle.net/thebeebs/tGzna/2/
The triangle colour looks fine across All major browsers to me. All I can think is that the CSS you are using in the picture differs from the CSS you have added in the question (which is possible since there is a black background to the div in your image), somthing on the page in which the code is embeded is effecting the color or there is something undernearth the arrow that is effecting the 0.9 alpha.
I also added something in the background to see if this effected Canvas elements and Div's with Alpha backgrounds differently... but it didn't seem to.