Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Wy StyleNormal().Write() is global?
Wy StyleNormal().Write() is global? [message #40706] Sat, 07 September 2013 18:57 Go to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I need to set own background image for buttons:

Button::Style &s1 = btn1.StyleNormal().Write();
s1.look[0] = img1;
s1.look[1] = img1;
s1.look[2] = img1;
s1.look[3] = img1;
s1.pressoffset = Point(1, -1);

Button::Style &s2 = btn2.StyleNormal().Write();
s2.look[0] = img2;
s2.look[1] = img2;
s2.look[2] = img2;
s2.look[3] = img2;
s2.pressoffset = Point(1, -1);

But after this btn1 also have img2 instead img1.
Re: Wy StyleNormal().Write() is global? [message #40707 is a reply to message #40706] Sat, 07 September 2013 19:19 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

iST1 wrote on Sat, 07 September 2013 18:57

I need to set own background image for buttons:

Button::Style &s1 = btn1.StyleNormal().Write();
s1.look[0] = img1;
s1.look[1] = img1;
s1.look[2] = img1;
s1.look[3] = img1;
s1.pressoffset = Point(1, -1);

Button::Style &s2 = btn2.StyleNormal().Write();
s2.look[0] = img2;
s2.look[1] = img2;
s2.look[2] = img2;
s2.look[3] = img2;
s2.pressoffset = Point(1, -1);

But after this btn1 also have img2 instead img1.

Hi,

StyleNormal() is a static method, hence it must only affect global properties Smile I think what you want is SetStyle() on the particular widget. What you are trying to do would look something like this (note: I haven't tested it):
	Button::Style s1 = Button::StyleNormal();
	s1.look[0] = img1;
	s1.look[1] = img1;
	s1.look[2] = img1;
	s1.look[3] = img1;
	s1.pressoffset = Point(1, -1);
	btn1.SetStyle(s1);
	
	Button::Style s2 = Button::StyleNormal();
	s2.look[0] = img1;
	s2.look[1] = img1;
	s2.look[2] = img1;
	s2.look[3] = img1;
	s2.pressoffset = Point(1, -1);
	btn2.SetStyle(s2);

The basic idea is to create a new style by copying and modifying the default one, then assigning the new style to your button.

Best regards,
Honza
Re: Wy StyleNormal().Write() is global? [message #40708 is a reply to message #40707] Sat, 07 September 2013 19:31 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Unfortunately,
	Button::Style s1 = Button::StyleNormal();
	s1.look[0] = img1;
	s1.look[1] = img1;
	s1.look[2] = img1;
	s1.look[3] = img1;
	s1.pressoffset = Point(1, -1);
	btn1.SetStyle(s1);

has no image-effect. Also button's boundary is removed.
Re: Wy StyleNormal().Write() is global? [message #40709 is a reply to message #40706] Sat, 07 September 2013 20:33 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
It got: variable "Button::Style s;" must be defined in global space, for example, as a class variable!
Re: Wy StyleNormal().Write() is global? [message #40746 is a reply to message #40709] Thu, 12 September 2013 18:48 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
It is possible to switch button's look programmatically without mouse click?
Button btn_;//in global space or in class
Button::Style styleBtn_;//in global space or in class
....
SetButtonImgStyle(btn_, styleBtn_, img0, img1, img2, img3);

btn_.Disable(); //=> img3

//btn must be enabled, but with look img3:
btn_.Enable();
btn_.State(3);//Nothing has changed

...
void SetButtonImgStyle(Button &btn, Button::Style &style, 
	const Image &img1, const Image &img2, const Image &img3, const Image &img4)
{
	style = Button::StyleNormal();
   	style.look[0] = img1;
   	style.look[1] = img2;
   	style.look[2] = img3;
   	style.look[3] = img4;
        style.pressoffset = Point(1, -1);

        btn.SetStyle(style);
	
	//size as image
	Size imgSize = img2.GetSize();
	Button::LogPos btnPos = btn.GetPos();
	
	btn.LeftPos(btnPos.x.GetA(), imgSize.cx);
	btn.TopPos(btnPos.y.GetA(), imgSize.cy);
}

[Updated on: Thu, 12 September 2013 18:49]

Report message to a moderator

Re: Wy StyleNormal().Write() is global? [message #40748 is a reply to message #40746] Thu, 12 September 2013 19:42 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
The hook is to modify GetVisualState function
int Pusher::GetVisualState() const
{
	//todo: add
	return !IsShowEnabled() ? CTRL_DISABLED :
	       IsPush() ? CTRL_PRESSED :
	       HasMouse() ? CTRL_HOT :
	       pseudoDisable ? CTRL_DISABLED : CTRL_NORMAL;
}

by adding boolean variable pseudoDisable:
class Pusher : public Ctrl {
public:
    //todo: add
    bool pseudoDisable;
...


Pusher::Pusher() {
    ...
    pseudoDisable = false;
}


Usage:
	btn_.pseudoDisable = true;
	btn_.Refresh();
Re: Wy StyleNormal().Write() is global? [message #40749 is a reply to message #40709] Thu, 12 September 2013 20:10 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
iST1 wrote on Sat, 07 September 2013 14:33

It got: variable "Button::Style s;" must be defined in global space, for example, as a class variable!


Well, it can be instance variable (e.g. of class derived from Button) as well. It just has to exist all the time while it is assigned to Button...

Mirek
Previous Topic: PATCH: plugin/jpg CMYK support
Next Topic: Transparent Background - Image control
Goto Forum:
  


Current Time: Thu Mar 28 20:50:19 CET 2024

Total time taken to generate the page: 0.01698 seconds