Updating the wxBitmap on wxBitmap - wxwidgets

I'm using a single wxButton:
wxButtonAction::wxButtonAction(wxWindow* parent) : wxButton(parent,wxID_ANY) {
#if defined __WXMSW__
wxIcon ms_icon(wxT("START_ICON"), wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
wxBitmap button_bmp;
button_bmp.CopyFromIcon(ms_icon);
#else
wxFileName icon_path(DATA_DIR, wxT("start.ico"));
wxBitmap button_bmp(icon_path.GetFullPath(), wxBITMAP_TYPE_ICO);
#endif
SetLabel(_("&Start"));
SetBitmap(button_bmp);
}
The bitmaped button is show as expected. This method helps me change both bitmap and label when user clicks that button:
void wxButtonAction::updateOnAction(bool isRunning) {
#if defined __WXMSW__
wxIcon ms_icon((isRunning) ? wxT("STOP_ICON") : wxT("START_ICON"), wxBITMAP_TYPE_ICO_RESOURCE, 16, 16);
wxBitmap button_bmp;
button_bmp.CopyFromIcon(ms_icon);
#else
wxFileName icon_path(DATA_DIR, (!isRunning) ? wxT("stop.ico") : wxT("start.ico"));
wxBitmap button_bmp(icon_path.GetFullPath(), wxBITMAP_TYPE_ICO);
#endif
SetLabel((!isRunning) ? _("&Stop") : _("&Start"));
SetBitmap(button_bmp);
}
and now the resource file:
AAPP_ICON ICON DISCARDABLE "../data/app.ico"
ABOUT_ICON ICON "../data/about.ico"
CLOSE_ICON ICON "../data/close.ico"
START_ICON ICON "../data/start.ico"
STOP_ICON ICON "../data/stop.ico"
1 24 "../data/manifest.xml"
The label is changed propertly when the user toggle clicking the button, but not the icon is always in "start" bitmap. I can confirm that all icons exists in the same folder

You don't need to use CopyFromIcon() at all, there is an implicit conversion from wxIcon to wxBitmap under MSW (because under the other platforms they're exactly the same thing). This being said, calling it explicitly should still work, so it's not clear what the problem is.
I'd like to recommend two other things: first, prefer using PNG (with real alpha transparency) to ICO nowadays. You might find wxBITMAP_PNG() useful to avoid the preprocessor checks, too.
Second, remove the manifest line from your .rc file and add #include "wx/msw/wx.rc" instead. This will do the right thing for the manifest and also define other stuff needed by wxWidgets applications.

Related

Correct GTK CSS selector to use from SWT widgets?

I'm trying to apply GTK+ 3 CSS rules to widgets used in the Eclipse UI, specifically for a ComboBox right now. For example: say I want to make the background color of a selected text in a combobox to be red. The Style rule applied to the combobox widget would be
*.entry:selected { background-color: #FF0000; }
I have proven that rule using the Gtk+ CSS Inspector tool in Ubuntu and that works there but I do not find a way to apply that rule in code for ComboBoxes.
Inside SWT, there are places where CSS is used on Linux, such as this snippet to set the background color, however, adding the above rule to the CSS override does not have any apparent impact (yes, the background color does work).
#Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
// CSS to be parsed for various widgets within Combo
background = rgba;
String css = "* {\n";
if (rgba != null) {
String color = display.gtk_rgba_to_css_string (rgba);
css += "background: " + color + ";\n";
}
css += "}\n";
// Cache background color
cssBackground = css;
String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);
//Injected code to make selected text red
finalCss += "\n.*:selected {background-color: #FF0000}";
if (entryHandle == 0 || (style & SWT.READ_ONLY) != 0) {
// For read only Combos, we can just apply the background CSS to the GtkToggleButton.
gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(buttonHandle), finalCss);
} else {
if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
// For GTK3.16+, only the GtkEntry needs to be themed.
gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(entryHandle), finalCss);
} else {
// Maintain GTK3.14- functionality
setBackgroundColorGradient (OS.gtk_widget_get_style_context (entryHandle), handle, rgba);
super.setBackgroundColor (OS.gtk_widget_get_style_context (entryHandle), entryHandle, rgba);
}
}
// Set the background color of the text of the drop down menu.
OS.g_object_set (textRenderer, OS.background_rgba, rgba, 0);
}
I’ve tried various combinations of selectors and so far have not found a way to have the “selection” background color of the text to take effect.
Here is a link to the corresponding ComboBox class from SWT where it deals with CSS -- see the setBackgroundColor method.
https://github.com/eclipse/eclipse.platform.swt/blob/master/bundles/org.eclipse.swt/Eclipse%20SWT/gtk/org/eclipse/swt/widgets/Combo.java
I have proven that code runs and also managed to change the background for the entire combobox by changing the css rule there. However, if I inject my new rule it gets ignored.
Any help would be appreciated. Thanks!

Custom QLineEdit, focusProxy and QDataWidgetMapper

This problem is driving me nuts so I would appreciate some assistance. Obviously done the usual googling and checking qt docs but have not found any solution.
We need to customize a standard QLineEdit. Here is a prototype:
class MyLineEdit : public QLineEdit
{
Q_OBJECT
public:
MyLineEdit(QWidget* a_parent)
{
QTextEdit* textEdit = new QTextEdit(this);
textEdit->setMinimumWidth(width() / 2);
textEdit->setMaximumWidth(width() / 2);
textEdit->setMinimumHeight(30);
textEdit->setTabChangesFocus(true);
// background color red
QPalette p = textEdit->palette();
p.setColor(QPalette::Base, QColor(244,20,20));
textEdit->setPalette(p);
textEdit->setVisible(true);
setFocusProxy(textEdit);
}
};
This shows a QLineEdit with a QTextEdit on-top of it.
Using the keyboard to change focus works as expected (the TextEdit gets the focus and not the LineEdit).
Using the mouse to change focus works as expected (selecting the LineEdit forwards the focus to the TextEdit).
The MyLineEdit and regular QLineEdit instances are added to a QDataWidgetMapper. We obviously use setModel method call on the QDataWidgetMapper instance.
In the QDialog, changing focus from a QLineEdit using keyboard or mouse triggers an invocation of our implementation of QAbstractItemModel::setData.
In the same QDialog, changing focus from a MyLineEdit using keyboard or mouse does NOT trigger an invocation of our implementation of QAbstractItemModel::setData.
This problem seems to be related to the setFocusProxy API. When removing setFocusProxy line;
changing focus from a MyLineEdit (specifically the QLineEdit) using keyboard or mouse does trigger an invocation of our implementation of QAbstractItemModel::setData.
changing focus from a MyLineEdit (specifically the QTextEdit) does NOT trigger an invocation of our implementation of QAbstractItemModel::setData.
How can I use setFocusProxy and get invocation of QAbstractItemModel::setData?
What am I doing wrong?

Strange indentation upon code formatting with MonoDevelop (double indentation)

When I use code formatting with MonoDevelop (Shortcut: Ctrl+I), everything gets double-indented:
namespace Example
{
public class Test
{
public static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("{0}: Test", i);
}
//this would be the desired indentation width!
//Not this!
}
}
}
Checking with the preferences under Source Code -> Code Formatting -> C# source code under Text Style, Tab width and Indent width are set to 4. Nevertheless, I get an indent width of 8 instead of 4, so twice as much indentation.
I'm working on a team-project with Unity3D and using MonoDevelop-Unity version 4.0.1.
It turned out that the solution/project itself had a different code formatting applied and it was overriding my settings from the preferences.
To adjust the solution/project specific settings, right click on the Solution/Project and choose Options. Under Source Code->Code Formatting->C# source are the actual tab width and indent width settings for this solution/project that are applied upon code formatting.

How to enable antialiasing (4X MSAA) for AndroidGameView?

I have a simple OpenGL application which I'm trying to enable antialiasing (4x MSAA) for. I can't seem to figure out how to do this using AndroidGameView.
So far I've been forcing 4x MSAA through the Developer Settings menu as a short term solution but I'd like to be able to do this programmatically. Can anyone shed some light on this?
Turns out that the way to do this programmatically is to set the GraphicsMode property in the CreateFrameBuffer() override of your class inheriting from AndroidGameView:
protected override void CreateFrameBuffer()
{
// Create a graphics context for OpenGL ES 2.0
ContextRenderingApi = GLVersion.ES2;
// Set the graphics mode to use 32bpp colour format, 24bpp depth, 8bpp stencil and 4x MSAA
GraphicsMode = new GraphicsMode(new ColorFormat(32), 24, 8, 4);
// Create the frame buffer itself by calling the base class method
base.CreateFrameBuffer();
// Custom initialization code here
}
Thanks to Cheesebaron for leading me down the path of looking into the GraphicsMode property of AndroidGameView.

Find the location of the Dock programmatically?

Is there a way in code to find out if the Dock on a Mac is located on the bottom, left, or right side of the user's monitor?
NSScreen has visibleFrame method, wich returns a rect that doesn't include the area currently occupied by the dock and menu bar. You can compare this rect with the full screen rect(- (NSRect) [NSScreen* frame]) and determine the dock location.
This is probably simpler…
defaults read com.apple.dock "orientation"
bottom
You can also find out.. autohide (i.e. 1), large size (i.e. "65.48148") and magnification (i.e. 1), etc.
private discovered API used by prefs panel
typedef enum {
kCoreDockOrientationTop = 1,
kCoreDockOrientationBottom = 2,
kCoreDockOrientationLeft = 3,
kCoreDockOrientationRight = 4
} CoreDockOrientation;
extern void CoreDockGetOrientationAndPinning(CoreDockOrientation *outOrientation, CoreDockPinning *outPinning);
// If you only want to set one, use 0 for the other.
extern void CoreDockSetOrientationAndPinning(CoreDockOrientation orientation, CoreDockPinning pinning);