I am running the sample code from msdn.
// Turn the marquee animation on or off.
void CCProgressCtrl_s1Dlg::OnSetmarqueeOn()
{
m_progressCtrl.SetMarquee(TRUE, nMarqueeInterval);
}
void CCProgressCtrl_s1Dlg::OnSetmarqueeOff()
{
m_progressCtrl.SetMarquee(FALSE, nMarqueeInterval);
}
This works but the problem is when marquee is off, the progress bar stays frozen at the instance. So if the moving light was in the middle at the time it will just freeze in that position. I want to reset the marquee when I turn it off but couldn't find any function for that. I tried SetPos(0) but that doesn't help either. Is there a way to reset the marquee progress bar once it has been sprang into action?
You have to remove the ProgressBar's PBS_MARQUEE window style, such as with CWnd::ModifyStyle(), before you can then change the position to whatever value you want. Enable the PBS_MARQUEE style only when you are in marque mode, and disable it when not.
void CCProgressCtrl_s1Dlg::OnSetmarqueeOn()
{
m_progressCtrl.ModifyStyle(0, PBS_MARQUEE);
m_progressCtrl.SetMarquee(TRUE, nMarqueeInterval);
}
void CCProgressCtrl_s1Dlg::OnSetmarqueeOff()
{
m_progressCtrl.SetMarquee(FALSE, nMarqueeInterval);
m_progressCtrl.ModifyStyle(PBS_MARQUEE, 0);
m_progressCtrl.SetPos(0);
}
Related
I'm doing a piano application thought to be played on mobile devices (Android). All the piano keys are UI buttons that have the "property" pressed color to a grey one in order to properly indicate when a piano key is emiting sound.
My current problem is that when I first click on a key and after that I drag the mouse over the following keys, only the first one that I clicked is getting the change of color (the idea is that the change of color duration finishes when other key starts sound and then the new key where I pass the mouse-finger gets the grey color).
I also tryied setting the higlighted color property to the same color as the pressed color with the Navigation parameter to none (if it's set to automatic it happens some kind of bug that the color is getting "stuck" until I make sound another key), but the result it's still the same.
EDIT:
I update the issue with some progress thath I made:
I'm trying to change the pressed color with a script thanks to the events Pointer enter and exit (both events are placed on a Event trigger in every button).
Code:
public class ChangeKeyColor : MonoBehaviour{
public Button button;
void Start()
{
}
void Update()
{
}
public void EnterKey () {
Debug.Log("Enter the key");
ColorBlock colors = button.colors;
colors.normalColor = new Color(179, 179, 179, 255);
//colors.highlightedColor = new Color32(179, 179, 179, 255);
button.colors = colors;
}
public void ExitKey()
{
Debug.Log("Exits the key");
ColorBlock colors = button.colors;
colors.normalColor = Color.white;
//colors.highlightedColor = new Color32(255, 255, 255, 255);
//colors.pressedColor = Color.white;
button.colors = colors;
}
}
The only improvement that I obtained is that now when I'm dragging the mouse (maintaning it) the first button returns to white color, but I think that this is happening because now I only setted to gray color the pressed color option...
Does anyone know why the pressed color change that I'm making in the script isn't happening? When I drag the mouse to another key isn't considered as a pressed button?
Regards!
I'm not sure if you are still looking for the answer, but I finally had some time to try it myself.
What I did is changing color and debug-logging transform's name instead of playing sound.
My code for Images/Buttons (attached to each Image, I didn't use Button components):
using UnityEngine;
using UnityEngine.UI;
public class ChangeColor : MonoBehaviour {
public Color activeColor, notActiveColor;
private Image thisImage;
void Awake () {
thisImage = GetComponent<Image>();
}
public void OnPointerClick()
{
Activate();
}
public void OnPointerEnterAndDown()
{
if (Input.GetKey(KeyCode.Mouse0))
{
Activate();
}
}
public void OnPointerExit()
{
thisImage.color = notActiveColor;
}
private void Activate()
{
Debug.Log(transform.name);
thisImage.color = activeColor;
}
}
EventTrigger settings:
And this is what it looks like in the end:
(This should be a comment, but it's a little long, so reply me and I'll update the answer)
I don't know why are you having this problem, I do the simple test creating 2 UI Buttons and setting the highlighted color to red, and the pressed to blue.
By default (there's no script attached to anything) the behaviour is the follow:
1.If I press (and mantain) the click on a button, that button is blue, when I release the "pression", the button keeps red.
2.While this first button is red, if I drag the mouse over the second button, this will be also red.
3.If now I press on the second button, the first behaviour applies to the second button, and the first one will be white again.
This is the following behaviour that you want, according to what I understood.
So, if this is not the desired behaviour, tell us more about what you want.
I have a 3d-object (cube), which I want to use as a button. I've written the code in order to detect, if the cube was pressed but it doesn't look like it was pressed, since it lacks the "clicking animation". How can I create a clicking animation on my 3d-object ?
A good idea is to play an aninimation which skrinks the cube a bit and releases it immediately afterwards. The handler code you want to execute on a click might block the game loop, e.g. when you load a level. Then it might be useful to load the level aysnchronously to be able to see the animation. Or you execute the handler code after the animation. Or you play the scale down animation on the press event and the scale up animation on the release event.
Technically you can use the build in animation editor, the Update() method, start a coroutine or use the assets iTween or HOTween.
http://docs.unity3d.com/ScriptReference/Transform-localScale.html
Let me know if you like the idea or questions arise.
Unity makes it easier now to do this using Unity Canvas UI. Instead of real 3d buttons, you could place a canvas UI in world space at the location where you want the buttons. Add a UI Panel to the canvas then add a UI Button.
Now, you have out of the box several clicking effects. The default it color tint, but you can choose sprite swap, or animation.
If you do want animation, when you select button animation it will create an animator for you. Click on your UI button Game Object in the scene hierarchy and open the animation window. You can choose Pressed animation from the drop down, and press RECORD button, then edit your buttons scale, say make it 0.75 for x,y,z. Now when you click on the button it will animate a cool scale down for you.
Sorry, I know that is a lot of information dumped! But you will find it pretty great once you start working with it in world space.
You can scale it down a tiny bit once click happen. For example:
void OnMouseDown() {
this.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
}
Then after click scale it back to the original size.
Perhaps look into iTween (free on Unity Asset store).
Its very easy to use and you can produce some nice looking animations.
you can scale it when pressed or just change the color a little bit. On mouse up, rescale or recolor it.
void OnMouseDown()
{
transform.localScale -= new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color += new Color(40,40,40);
}
void OnMouseUp()
{
transform.localScale += new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color -= new Color(40,40,40);
}
You can implement your button using new Event system of unity. Here are the functions you can implement :
public class ExampleClass : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
//it is the function when you hover your mouse to the object
//You can change the color of your object to make your users
//understand that it is not just a cube but also a clickable item
}
public void OnPointerExit(PointerEventData eventData)
{
//You can revert your color back to its original
}
public void OnPointerDown (PointerEventData eventData)
{
//You can play with local scale as suggested by other answers here
}
public void OnPointerUp (PointerEventData eventData)
{
// Revert back the changes you made at onPointerDown
}
public void OnPointerClick (PointerEventData eventData)
{
//Use here for operations when your button is clicked
}
}
I receive a Leave Event every time i move a pixel with my mouse over a customized QFrame i did. Why is this happening?.
I reimplemmented the leave and enter event as follows. As you can see i tried to comment the QFrame enterEvent, and restrict the repetition with a boolean, but it doesnt work because an enter and leave are continuously generated:
void enterEvent( QEvent *event ){
//QFrame::enterEvent(event);
if (!mouseHover_)
{
mouseHover_ = true;
emit hoverInSignal("");
}
}
void leaveEvent( QEvent *event ){
//QFrame::leaveEvent(event);
if (mouseHover_)
{
SmartUIWrapper::Instance()->addInfoMessage("out");
emit hoverOutSignal();
mouseHover_ = false;
}
}
Does it have something to be with the focus?
I discovered the reason.
I created a panel over this QFrame when i hovered.
When i moved the mouse, since the panel is positioned on the right bottom side of the cursor position, everytime i moved over the QFrame to the right or bottom, when i hovered this new panel i created, it looses the focus, so it gets closed again, then another hover comes, and then it´s created again... and again... everytime i hover the new panel.
How do I disable the "elastic" scrolling in a BlackBerry PaneManagerModel/View and HorizontalScrollableTitleView/HorizontalScrollableController?
I mean: when I drag the leftmost pane to the right (dragging the title bar), the white background appears, and when I lift my finger, it bounces back.
I find it very annoying, I suppose it's a feature of the PaneManagerView, or the HorizontalScrollableTitleView, can I disable it?
What about adding a ScrollChangeListener to the View that adjusts the scroll whenever it goes beyond the bounds? For example:
public void scrollChanged(Manager mgr, int newHorizScroll, int newVertScroll) {
if (newHorizScroll < 0) {
setHorizontalScroll(0);
}
// and so on
}
I'm using a CControlBar-derived class and I would like to detect when the docking state of the CControlBar has changed (i.e., docking from vertical to horizontal or when it goes into floating mode).
Of course, I could handle WM_SIZE but it seems to be a waste of ressources doing the task every time a WM_SIZE message is fired instead of only when the docking state has changed.
Can anyone please point me in the right direction?
You can override the CControlBar::OnBarStyleChange virtual function to detect changes in the control bar style (CBRS_XXX values - look in the <afxres.h> header file for details).
To determine whether the control bar is floating/docked, check the CBRS_FLOATING style. To check for horizontal/vertical orientation, use the CBRS_ORIENT_HORZ and CBRS_ORIENT_VERT styles.
So, using CToolBar (which is derived from CControlBar) as an example:
class CMyToolBar : public CToolBar {
public:
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
};
void CMyToolBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
// Call base class implementation.
CToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
// Use exclusive-or to detect changes in style bits.
DWORD changed = dwOldStyle ^ dwNewStyle;
if (changed & CBRS_FLOATING) {
if (dwNewStyle & CBRS_FLOATING) {
// ToolBar now floating
}
else {
// ToolBar now docked
}
}
if (changed & CBRS_ORIENT_ANY) {
if (dwNewStyle & CBRS_ORIENT_HORZ) {
// ToolBar now horizontal
}
else if (dwNewStyle & CBRS_ORIENT_VERT) {
// ToolBar now vertical
}
}
}
I hope this helps!