nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * Gordon Allott <gord.allott@canonical.com> 00020 * 00021 */ 00022 00023 #include "Nux.h" 00024 #include "AbstractButton.h" 00025 #include "HLayout.h" 00026 00027 namespace nux 00028 { 00029 NUX_IMPLEMENT_OBJECT_TYPE(AbstractButton); 00030 00031 AbstractButton::AbstractButton(NUX_FILE_LINE_DECL) 00032 : View(NUX_FILE_LINE_PARAM) 00033 , state(NUX_STATE_NORMAL) 00034 { 00035 active = false; 00036 togglable_ = false; 00037 Init(); 00038 } 00039 00040 AbstractButton::~AbstractButton() 00041 { 00042 00043 } 00044 00045 void AbstractButton::Init() 00046 { 00047 mouse_click.connect(sigc::mem_fun(this, &AbstractButton::RecvClick)); 00048 mouse_down.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseDown)); 00049 mouse_double_click.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseDown)); 00050 mouse_up.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseUp)); 00051 mouse_move.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseMove)); 00052 mouse_enter.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseEnter)); 00053 mouse_leave.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseLeave)); 00054 } 00055 00056 long AbstractButton::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00057 { 00058 return PostProcessEvent2 (ievent, TraverseInfo, ProcessEventInfo); 00059 } 00060 00061 void AbstractButton::RecvClick(int x, int y, unsigned long button_flags, unsigned long key_flags) 00062 { 00063 if(togglable_) 00064 { 00065 active = !active; 00066 } 00067 else 00068 { 00069 active = true; 00070 } 00071 00072 if(togglable_ == false) 00073 { 00074 active = false; 00075 } 00076 00077 activated.emit(this); 00078 QueueDraw(); 00079 } 00080 00081 void AbstractButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) 00082 { 00083 state = NUX_STATE_PRELIGHT; 00084 //state = 1; 00085 QueueDraw(); 00086 } 00087 00088 void AbstractButton::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) 00089 { 00090 state = NUX_STATE_ACTIVE; 00091 QueueDraw(); 00092 } 00093 00094 void AbstractButton::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 00095 { 00096 00097 } 00098 00099 void AbstractButton::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) 00100 { 00101 state = NUX_STATE_PRELIGHT; 00102 QueueDraw(); 00103 } 00104 00105 void AbstractButton::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) 00106 { 00107 state = NUX_STATE_NORMAL; 00108 QueueDraw(); 00109 } 00110 }