RadioButton in codenameone chaning the checkmark or color style - radio-button

I am facing problems changing the checkmark on the radiogroup, or color, I appreciate the help
I tried the StyleBuilder, changed the font colors, but failed to change the side mark that shows the selected radiobutton
sample
thank you,

If you have static images, you can change RadioButton icons through constants in your theme.res. The applicable constants are:
radioUnselectedImage
radioUnselectedDisImage
radioSelectedImage
radioSelectedDisImage
If you don't have static images or you want to set the images dynamically in code, you may call below (before your RadioButton declaration):
float sizeMM = 3f;
int size = Display.getInstance().convertToPixels(sizeMM);
int blue = 0x73b5e3;
int white = 0xffffff;
FontImage checkedImage = FontImage.createFixed("" + FontImage.MATERIAL_CHECK, FontImage.getMaterialDesignFont(),
blue, size, size, 0);
FontImage uncheckedImage = FontImage.createFixed("" + FontImage.MATERIAL_CHECK, FontImage.getMaterialDesignFont(),
white, size, size, 0);
((DefaultLookAndFeel) UIManager.getInstance().getLookAndFeel())
.setRadioButtonImages(checkedImage, uncheckedImage, checkedImage, uncheckedImage);
((DefaultLookAndFeel) UIManager.getInstance().getLookAndFeel())
.setRadioButtonFocusImages(checkedImage, uncheckedImage, checkedImage, uncheckedImage);
Note: DefaultLookAndFeel is deprecated and may cause weird behavior, use it with caution.

Related

SpriteKit displaying variable number

What is the best way to display some value (that changes as the game runs) on the screen in iPhone SpriteKit? The only way I can think of is SKLabelNode, but it's probably not meant to be used like this and also I can't find any way to measure its width, which makes me unable to position it correctly (I want it to be in the bottom right corner). Thanks in advance :).
#Edit
My attempt at doing this:
SKLabelNode *someLabel = [SKLabelNode labelNodeWithFontNamed:#"Chalkduster"];
someLabel.text = some_string;
someLabel.fontSize = 30;
someLabel.fontColor = [SKColor blackColor];
someLabel.position = CGPointMake(some_int, 15);
[self addChild:someLabel];
The values of some_string and some_int change as the game runs, so someLabel is removed, someLabel.text and someLabel.position are re-assigned, and the label is added again. Yes, I am aware that this is a bad way to do this...
Unfortunately, SKLabelNode is your simplest bet, it's just not the most robust tool.
You just want to update its text and its position when you need to. Your code is correct, and if you want to get its actual size, then you would get the width of its frame.
update text:
someLabel.text = theNewText;
update position:
someLabel.position = theNewPosition;
get relative width
float widthOfLabelFrame = someLabel.frame.size.width;
additional alignment settings that might help (vertical baseline is the default):
someLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeRight;
someLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeBaseline;

PySide: Resizable scene in QGraphicsView

I'm trying to find a way to mark the border of a QGraphicsScene, and make it resizable inside a QGraphicsView, to create something similar to Microsoft Paint.
In other words, my current QGraphicsView looks like this:
But my image is only this big, as indicated by the red box:
I want my QGraphicsView to be like this (the little black boxes are cornergrabbers for resizing the canvas):
Functionally, I want it to be similar to MS Paint:
The canvas (scene) is resizable, and the scrollbars on the window (view) appear when needed. The blue background color (solid gray background) appears behind the canvas.
How would I go about accomplishing this?
To try to get the grey background, I've been experimenting with QGraphicsView.setBackgroundBrush() and QGraphicsScene.setBackgroundBrush(). I've learned that QGraphicsView's background brush completely overrides QGraphicsScene's background brush if one is set. Even if I only set the background brush for QGraphicsScene, that background brush extends over the image's original boundaries.
Here is a link to my test code.
Help is appreciated!
I have to struggle with your constructors...dunno if it works on Windows, but have to make it to work with Linux. Try :
def setPixmap(self, pixmap):
if self.pixmap_item:
self.removeItem(self.pixmap_item)
self.pixmap_item = self.addPixmap(pixmap)
self.setPixBackGround()
def setPixBackGround(self):
# put Background rect for image
pixR = self.pixmap_item.pixmap().rect()
bgRectangle = self.addRect(pixR.x()-10, pixR.y()-10,
pixR.width()+20, pixR.height()+20)
# set color and Z value to put it behind image
bgColor = QColor(58, 176, 176)
bgRectangle.setBrush(bgColor)
bgRectangle.setZValue(-.1)
# take coordinates for brabbers
bgR = bgRectangle.rect()
grab1R = QRect(-5,-5,10,10)
# put grabbers as wish...
grab1 = self.addRect(grab1R)
grab1.setPos(bgR.topLeft())
grab2 = self.addRect(grab1R)
grab2.setPos(bgR.topRight())
# ....etc....

How to resize image to a fixed height and width without losing aspect ratio in winjs?

I have an image area in my application with width:530px and height:510px. I want to place images in that area but the images comes in different different sizes. how to crop or scale the image without losing aspect ratio to fill that area. Is there any native methods available in winjs?
You have a few options for that.
One is to use the ViewBox control that WinJS provides you. The ViewBox can only have a single child (so you would have your tag as its only child perhaps or a div that contains your img) and it will scale that child (using CSS transforms) up to fit into its container (without changing the aspect ratio). It's pretty slick.
Another option is to set the image as the CSS background-image property of a container (such as a div) and set the background-size property to contain. This will stretch the image up to the size of the container.
A final option that you have to resort to if your case is a bit special is not such a bad option after all. In the updateLayout method of your page, you can refer to the element and explicitly set its CSS properties to fit. At that point you'll know all about the layout and can easily do the math to figure out what size image should be. Here's some code from one of my projects where I do this. Notice that I'm comparing the aspect ratio of the screen and the image to determine whether I should size to the width or the height. Unlike your situation (I'm guessing), my code makes sure the image fills the screen and excess is clipped. I'm guessing you want your img to be contained.
function setImagePosition() {
var img = q(".viewCamera #viewport img");
if (outerWidth/outerHeight > img.naturalWidth/img.naturalHeight) {
img.style.width = format("{0}px", outerWidth);
img.style.height = "";
img.style.top = format("{0}px", (outerHeight - img.clientHeight) / 2);
img.style.left = "0px";
} else {
img.style.width = "";
img.style.height = format("{0}px", outerHeight);
img.style.top = "0px";
img.style.left = format("{0}px", (outerWidth - img.clientWidth) / 2);
}
}
Hope that helps!
Are you referring to scaling HTML images? If so, you can set either one, width or height. Whichever you set, the other will scale and keep image aspect ratio.

How to change the size and color of Petrel "Attributes Labels" using Ocean

I add a property to a PolylineSet using the code below (In the Petrel UI they are named “Attribute labels”)
using (ITransaction trans = DataManager.NewTransaction())
{
trans.Lock(polylineSet);
PolylinePropertyCollection ppc = polylineSet.CreatePropertyCollection();
trans.Lock(ppc);
property = ppc.CreateProperty(PetrelProject.WellKnownTemplates.MiscellaneousGroup.General, name);
trans.Commit();
}
I would like to change the size and color.
Does anyone know if this is possible via Ocean?
I want to do this because these labels have a size of 1 and color black and it isn't a good default for me.
Thanks in advance
I haven't specifically altered the color and size of labels, but have dealt with size and color for polylinesets. Maybe you can use the INumberAnnotation style object? It seems to have properties for setting font color and size.
Slb.Ocean.Petrel.UI.Style.IStyleFactory factory = CoreSystem.GetService<Slb.Ocean.Petrel.UI.Style.IStyleFactory>(ppc);
Slb.Ocean.Petrel.UI.Style.INumberAnnotation style = (Slb.Ocean.Petrel.UI.Style.INumberAnnotation)factory.GetStyle(ppc, myWindow);
if (style != null)
{
style.FontColorType = Slb.Ocean.Petrel.UI.Style.ColorType.White;
style.FontSize = 400;
}
Hope that works.

Color.ToArgb relation between 5046311 and 14221235?

the form backcolor is 14221235 , but when i set the customcolor in colordialog to equal the form backcolor, it sets it to 5046311 !!! what is the problem?
this is how i am getting the background color:
get_background = Str(Abs(Form1.BackColor.ToArgb))
the reason i am turning it into a string is because i will feed it into a string which has "32498239, 234234234, 23423234, 32234432432, 423324234"
then i take this string and put it in customcolors like this. btw this piece of code works fine:
Dim numberStrings = My.Settings.mytext1.Split(","c).Select(Function(x) x.Trim())
ColorDialog1.CustomColors = numberStrings.Select(Function(x) CInt(x)).ToArray()
a user below mentioned that toargb takes into account the opacity. this is an excellent point indeed, and i want to clarify that i DO NOT need the opacity. how would i do toargb without taking into opacity?
this is what you want
Microsoft.VisualBasic.RGB(Me.BackColor.R, Me.BackColor.G, Me.BackColor.B).ToString
The 32-bit result from .ToArgb() contains not just the three visible color components (red, green and blue) but also the alpha component, which is essentially opacity. This is a pure guess on my part, but I think the ColorDialog is just used for picking RGB values, so when you set the color to the form's BackColor, the dialog just ignores the alpha component (or sets it to zero), which is why you end up getting a different number from the .ToArgb() method.
Note: this is just speculation on my part. It would help if you posted a code sample that demonstrates the specific problem.
I don't really understand the question. You want to set the custom color dialog CustomColor property to (the form's backcolor) r + g + b components? Not sure why you would do that, you can always just get the form's backcolor, set the Alpha value to 255 and then set the result to the CustomColor property:
Color c = Color.FromArgb( 255, form1.BackColor );
myColorDlg.CustomColor = c;
Or just use form1.BackColor.ToArgb() & 0xFFFFFF (if you want the integer value).
If you are asking for ARGB (A = Alpha) then you are asking for the opacity information. Instead you could use the R, G, B Properties of Color Independently.
You could use Color.FromArgb(255, me.BackColor).ToArgb() in order to get the ARGB value of the same color with 100% opacity.
To highlight how to pass the same colour (Using Fredou's answer) from a colorDialog to set a pie chart segment colour, one which is a .Net embedded chart and the other an Excel chart:
embchartPie.Series(0).Points(Index).Color = ColorDialog1.Color
With ColorDialog1.Color
xl_Pie_Chart.SeriesCollection(1).points(Index + 1).format.fill.forecolor.rgb = RGB(.R, .G, .B).ToString
End With