GUI/Window message system problem

Started by
9 comments, last by Ron AF Greve 12 years, 11 months ago
Well that is actually rather simple for instance a button just creates an event object and passes that to its parent which could handle it or send it to its parent until it hits the root of the hierarchy. Currently it is stored there. So it can be either read by a containing class wich then adds it to the scheduler or I created one big hierarchy (they all derive from a scripting class) and let the non-gui object that created the gui handle them directly.

Although I tested both my scripting and gui I haven't hooked them up yet. But this is how it currently looks when a component sends an event:



class MGUIEventId
{
private:
size_t Hash;
std::string Eventname;
SVRefPtr<VVar> Parameters; // SVRefPtr is my smartptr ( intrusive refcnt ) type

public:
MGUIEventId():
Hash ( ),
Eventname( )
{
}

// Probably should be constant, however it can't really be that way, since it reference counts also inside the variant (mutable would probably do)
SVRefPtr<VVar> GetParameters() { return Parameters; }

MGUIEventId( const std::string& Eventname ):
Eventname( Eventname )
{
std::hash<const char*> HashFunction;
Hash = HashFunction( Eventname.c_str() );
}

bool operator< ( const MGUIEventId& GUIEventId ) const
{
if( Hash < GUIEventId.Hash ) return true;
else if( Hash == GUIEventId.Hash )
{
return Eventname < GUIEventId.Eventname;
}
return false;
}

bool operator==( const MGUIEventId& GUIEventId ) const
{
return GUIEventId.Hash == this->Hash &&
GUIEventId.Eventname == this->Eventname
;
}

// ----Inspectors
const size_t& GetHash () const { return Hash ;}
const std::string& GetEventname() const { return Eventname;}

// ----Mutators
void SetHash ( const size_t& Hash ) { this->Hash = Hash ;}
void SetEventname( const std::string& Eventname ) { this->Eventname = Eventname;}

friend MChannel& operator<<( MChannel& Channel, const MGUIEventId& GUIEventId );
};

class MGUIEvent : public ISerializeScript
{
private:
MGUIEventId GUIEventId;
CLocation Location;

public:
MGUIEvent():
GUIEventId( ),
Location ( )
{
}

MGUIEvent( const std::string& Eventname, const CLocation& Location ):
GUIEventId( Eventname ),
Location ( Location )
{
}

bool operator< ( const MGUIEvent& GUIEvent ) const
{
if( GUIEventId < GUIEvent.GUIEventId ) return true;
else if( GUIEventId == GUIEvent.GUIEventId )
{
return Location < GUIEvent.Location;
}
return false;
}

bool operator==( const MGUIEvent& GUIEvent ) const
{
return GUIEvent.GUIEventId == this->GUIEventId &&
GUIEvent.Location == this->Location
;
}

// ----Inspectors
const MGUIEventId& GetGUIEventId() const { return GUIEventId;}
const CLocation& GetLocation () const { return Location ;}

// ----Mutators
void SetGUIEventId( const MGUIEventId&& GUIEventId ) { this->GUIEventId = GUIEventId;}
void SetLocation ( const CLocation& Location ) { this->Location = Location ;}

friend MChannel& operator<<( MChannel& Channel, const MGUIEvent& GUIEvent );
};


// ----------------------in MComponent
void MUIBase::Emit( const MGUIEvent& GUIEvent )

{

if( Parent )

{

Parent->Emit( GUIEvent );

}





}



void MComponent::Emit( const std::string Eventname, const CLocation& Location )

{

MUIBase::Emit( MGUIEvent( Name + "::" + Eventname, Location ) );

}

In the root of the hierarchy I overwirte various methods

void MWindowGroup::Emit( const MGUIEvent& GUIEvent )
{
Queue.push_back( GUIEvent );
}









edit: Ouch, forgot the most important thing, it needs a array of variants to pass on name-value pairs (the vvar contains a vvar map).
Ron AF Greve

This topic is closed to new replies.

Advertisement