I'm trying to pad an email field with the following snippet:
emailField = new BasicEditField(BasicEditField.FILTER_EMAIL|Field.FIELD_HCENTER|TextField.NO_NEWLINE|Field.HIGHLIGHT_FOCUS|Field.FOCUSABLE);
emailField.setLabel("Email: ");
emailField.setPadding(5, 5, 5, 5);
emailField.setBorder(BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0x0083B0D7, Border.STYLE_SOLID));
Is there a proper way to pad such that there appears no margin between the border and the field background?
Try using setMargin(5,5,5,5) instead of setPadding(5,5,5,5).
Field#setMargin()
Margin is the area outside a field, after the border. It is up to a manager to allocate margins properly since these overlap.
Field#setPadding()
Padding is the area within a field between the content and the border.
Field#SetBorder()
The border is the area within a field outside the padding and before the margin.
UPDATE:
Your are right, replacing setPadding() with setMargin() only, didn't produced the desired result. The reason is the Border you are using, to be more precise its thickness (10) and style (STYLE_SOLID). Decrease the border thickness to 3 and change it style to STYLE_FILLED.
After the aforementioned changes
And now the code snippet:
public class PlayingWithBorders extends MainScreen {
public PlayingWithBorders() {
super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.CYAN));
BasicEditField emailField = new BasicEditField();
emailField.setLabel("Email: ");
emailField.setPadding(5, 5, 5, 5);
emailField.setMargin(5, 5, 5, 5);
emailField.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x0083B0D7, Border.STYLE_FILLED));
emailField.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
BasicEditField passwordField = new BasicEditField();
passwordField.setLabel("Password: ");
passwordField.setPadding(5, 5, 5, 5);
passwordField.setMargin(5, 5, 5, 5);
passwordField.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x0083B0D7, Border.STYLE_FILLED));
passwordField.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
vfm.add(emailField);
vfm.add(passwordField);
add(vfm);
}
Related
I have the following question.
There is a model, through the setFromObject method I get Box3 (screenshot - http://prntscr.com/12787py). Next, I rotate the model and get a new Box3 (screenshot - http://prntscr.com/12789fy).
Is it possible after rotating the model to get Box3 with the same rotation, as if Box3 was rotating with the model?
Box3 is a mathematical representation of a box. As such, it is represented with only two Vector3 properties (max and min) that represent two opposing corners of the box. The values of these do not represent a box in full 3D space, but rather an axis-aligned box.
It looks like you're using BoundingBoxHelper. This creates a wireframe box that is world-aligned. This means it will compute its shape based on the transformed positions of the geometry vertices, and so it may change shape as your mesh is rotated.
To create a shape-tight wireframe box that rotates with your object, you will need to create one directly from your geometry, and ensure the same transformation is applied to both shapes.
// your shape
const shapeGeo = new BoxGeometry( 10, 10, 10 )
shapeGeo.computeBoundingBox() // <----------- DO THIS BEFORE ADDING IT TO THE SCENE!
const shapeMat = new MeshPhongMaterial( { color: 'red' } )
const shapeMsh = new Mesh( shapeGeo, shapeMat )
// your wireframe
const bboxMin = shapeGeo.boundingBox.min
const bboxMax = shapeGeo.boundingBox.max
const wireGeo = new BufferGeometry()
wireGeo.setAttribute( 'position' , new BufferAttribute( new Float32Array( [
bboxMin.x, bboxMin.y, bboxMin.z,
bboxMin.x, bboxMin.y, bboxMax.z,
bboxMin.x, bboxMax.y, bboxMax.z,
bboxMin.x, bboxMax.y, bboxMin.z,
bboxMax.x, bboxMin.y, bboxMin.z,
bboxMax.x, bboxMin.y, bboxMax.z,
bboxMax.x, bboxMax.y, bboxMax.z,
bboxMax.x, bboxMax.y, bboxMin.z,
] ), 3, false ) )
wireGeo.setIndex( new BufferAttribute( new Uint8Array( [
0, 1, 1, 2, 2, 3, 3, 0,
4, 5, 5, 6, 6, 7, 7, 4,
0, 4, 1, 5, 2, 6, 3, 7
] ), 1, false ) )
const wireMat = new LineBasicMaterial( { color: 'yellow' } )
const wireBox = new LineSegments( wireGeo, wireMat )
Now, here's where things take what might seem like an odd twist. Once you have your wire box, you can simply add it to your shape, and future changes to your shape will be passed on to your wire box:
scene.add( shapeMsh )
shapeMsh.add( wireBox )
This works because transformations are passed on to children*, and a Mesh is really just an extension of Object3D, so a Mesh can have children just like any other Object3D derivative.
* as long as you don't disable automatic matrix updates
I'm attempting to have an X-Axis with dates. Unfortunately my data can be have a small range resulting in a date showing multiple times as an xTick. Is there a way to force it to only show "each date" exactly once as a tick.
For example, I don't want to see 12/29/2020 as a tick more than once.
Depends on your version of d3, but d3.timeDay might be what you need.
var input = [new Date(1999, 11, 31, 0),new Date(2000, 0, 1, 0), new Date(2000, 0, 1, 2), new Date(2000, 0, 1, 3), new Date(2000, 0, 2, 2), new Date(2000, 0, 2, 5)];
console.log(input);
var x = d3.scaleTime().domain(input);
var xTick = x.ticks(d3.timeDay.every(1));
console.log(xTick)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
I have a dialog window created dinamically. There I have TextFields and ChoiceBoxes. Text fields fits column widths and ChoiceBoxes are not. Have a look at the pic:
I need choicebox to be of the same width as textField
elements are added in this way:
addingDialogPane.add(nameLabel, 0, 1);
addingDialogPane.add(name, 1, 1);
addingDialogPane.add(extUidLabel, 0, 2);
addingDialogPane.add(extUid, 1, 2);
addingDialogPane.add(is_folder, 0, 3);
addingDialogPane.add(parentLabel, 0, 4);
addingDialogPane.add(parent, 1, 4);
addingDialogPane.add(confirm, 1, 5);
UPD: I've tryed to use
parent.prefWidthProperty().add(name.getWidth());
no effect
I've also tryed
parent.prefWidth(double);
no effect
Set the maxWidth property of it to:
extUid.setMaxWidth( Double.POSITIVE_INFINITY );
parent.prefWidthProperty().bind(extUid.widthProperty());
I'm not sure whether SuperCollider can deliver moons on sticks, but I'd really like to be able to specify values in my Pbind that are interpreted in the same way as midinote or degree: i.e. converted automatically to a frequency.
So, an excerpt of such a Pbind, which produces a TB-303-style slide from one frequency to another:
b = Pbind(*[
out: 0,
instrument: \acid,
stepsPerOctave: 19,
scale: [0, 3, 5, 8, 11, 14, 17],
octave: 3,
degree: Pseq([0, \, 3, 3, 4, 4, 9, 4, 4]),
prevFreq: Pseq([\, \, 0, 3, 3, 4, 4, 9, 4]),
dur: Pseq([0.4, 0.4, 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1]),
]);
...it would be super-duper if prevFreq were interpreted as containing degree values in the same way as degree.
In the absence of some kind of automatic conversion, I assume I need to do some kind of calculation within the synth itself in order to convert my values from a degree-type value to an actual frequency. I'm aware I can use foo.midicps to convert midinote-type values to a frequency, but is there a similar convenience function to convert degree-type values to a frequency (presumably also using the current scale and octave values)?
If you look at the helpfile for Event, you can see how it computes the frequency from the degree and scale:
note: #{ // note is the note in halftone steps from the root
(~degree + ~mtranspose).degreeToKey(~scale, ~stepsPerOctave);
}
midinote: #{ // midinote is the midinote (continuous intermediate values)
((~note.value + ~gtranspose + ~root) / ~stepsPerOctave + ~octave) * 12.0;
}
freq: #{
(~midinote.value + ~ctranspose).midicps * ~harmonic;
}
detunedFreq: #{ // finally sent as "freq" to the synth as a parameter, if given
~freq.value + ~detune
}
Event is an associative array and those ~variables can also be used as keys to the array (something which will hopefully become clear in a moment. It's also possible to get access to the events in a Pbind, by using a Pfunc. Let's say we want to calculate the current frequency for your Pbind:
b = Pbind(*[
out: 0,
instrument: \default,
stepsPerOctave: 19,
scale: [0, 3, 5, 8, 11, 14, 17],
octave: 3,
degree: Pseq([0, \, 3, 3, 4, 4, 9, 4, 4]),
dur: Pseq([0.4, 0.4, 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1]),
foo: Pfunc({|evt|
var note, midinote, freq, detuned, result;
note = (evt[\degree] + evt[\mtranspose]).degreeToKey(evt[\scale], evt[\stepsPerOctave]);
midinote = ((note + evt[\gtranspose] + evt[\root]) / evt[\stepsPerOctave] + evt[\octave]) * 12.0;
freq = (midinote + evt[\ctranspose]).midicps * evt[\harmonic];
detuned = freq + evt[\detune];
detuned.postln;
})
]).play
Those calculations for note, midinote, freq and detuned freq are the same calculations we saw in the event helpfile. Therefore, this Pbind will now print out the frequency that you are currently playing.
What you actually want is the frequency you were previously playing, which we could figure out from your array of previous degrees. Or we could just keep track of the previous frequency in a variable. This will be a lot easier to keep track of!
(
var prev;
b = Pbind(*[
out: 0,
instrument: \default,
stepsPerOctave: 19,
scale: [0, 3, 5, 8, 11, 14, 17],
octave: 3,
degree: Pseq([0, \rest, 3, 3, 4, 4, 9, 4, 4]),
dur: Pseq([0.4, 0.4, 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1]),
prevFreq: Pfunc({|evt|
var note, midinote, freq, detuned, result;
if (evt[\degree] == \rest, { detuned = \rest} , {
note = (evt[\degree] + evt[\mtranspose]).degreeToKey(evt[\scale], evt[\stepsPerOctave]);
midinote = ((note + evt[\gtranspose] + evt[\root]) / evt[\stepsPerOctave] + evt[\octave]) * 12.0;
freq = (midinote + evt[\ctranspose]).midicps * evt[\harmonic];
detuned = freq + evt[\detune];
});
//detuned.postln;
if (prev.isNil(), {
result = \rest;
} ,
{
result = prev;
});
prev = detuned
})
]).play
)
I'm trying to detect circles but I am detecting circles that aren't even there. My code is below. Anyone know how to modify the DetectCircle() method to make the detection more accurate , please and thanks
void detectCircle( IplImage * img )
{
int edge_thresh = 1;
IplImage *gray = cvCreateImage( cvSize(img->width,img->height), 8, 1);
IplImage *edge = cvCreateImage( cvSize(img->width,img->height), 8, 1);
cvCvtColor(img, gray, CV_BGR2GRAY);
gray->origin = 1;
// color threshold
cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);
// smooths out image
cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);
// get edges
cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5);
// detects circle
CvSeq* circle = cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
edge->height/50, 5, 35);
// draws circle and its centerpoint
float* p = (float*)cvGetSeqElem( circle, 0 );
if( p==null ){ return;}
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0 );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0 );
cvShowImage ("Snooker", img );
}
cvHoughCircles detects circles that arent obvious to us. If you know the pixel size of snooker balls you can filter them based on their radius. Try setting the min_radius and max_radius parameters in your cvHoughCircles function.
On a side note, once you get the circles, you can filter them based on color. If the circle is mostly one color, it has a good chance of being a ball, if it doenst its probably a false positive.
edit: by "circle's color" i mean the pixels inside the circle boundary