Petals's profilePetals on a wet, black b...PhotosBlogListsMore ![]() | Help |
Petals on a wet, black bough |
||||
Public folders
|
July 02 How to force a point to sit on a rectangle ?rectange rec; /** * Force the point to sit inside (or on) rectangle. */ if ( point.x > rec.width ){ point.x = rec.width; } if ( point.x < 0.0 ){ point.x = 0.0; } if ( point.y > rec.height){ point.y = rec.height; } if ( point.y < 0.0 ){ point.y = 0.0; } /** * Force the point to sit on the rectangle. */ if ( point.x > (rec.width - point.x) ){ if (point.y > (rec.height - point.y) ){ if ( (rec.width - point.x) > (rec.height - point.y) ){ point.y = rec.height; } else{ point.x = rec.width; } } else{ if ( point.y > (rec.width - point.x) ){ point.x = rec.width; } else{ point.y = 0.0; } } } else{ if ( point.y > (rec.height - point.y) ){ if ( point.x > (rec.height - point.y) ){ point.y = rec.height; } else{ point.x = 0.0; } } else{ if ( point.x > point.y ){ point.y = 0.0; } else{ point.x = 0.0; } } } July 01 configure.ac tips-------------------------------------------------------------------------------------------------------------------------------------------- 1. configure.ac 和 Makefile.am 的对应: configure.ac: PKG_CHECK_MODULES([GLIBMM], [glibmm-2.4]) PKG_CHECK_MODULES([GTKMM], [gtkmm-2.4]) Makefile.am: AM_CPPFLAGS = \ $(GLIBMM_CFLAGS) \ $(GTKMM_CFLAGS) \ AM_LDFLAGS = \ $(GLIBMM_LIBS) \ $(GTKMM_LIBS) \ 2. AC_ARG_ENABLE的一个例子 dnl ================== Graphviz checks =============================== AC_ARG_ENABLE(gvc, [AC_HELP_STRING([--enable-gvc], [Compile with Graphviz support])], [case "${enableval}" in yes) enable_gvc=yes ;; no) enable_gvc=no ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-gvc) ;; esac], [enable_gvc=yes]) dnl Default value if test "x$enable_gvc" = "xyes"; then PKG_CHECK_MODULES([GVC], [libgvc], [enable_gvc=yes], [enable_gvc=no]) if test "x$enable_gvc" = "xyes"; then AC_DEFINE([ENABLE_GVC], [1], [Enable Graphviz support.]) else AC_DEFINE([ENABLE_GVC], [0], [Disable Graphviz support.]) AC_MSG_WARN("Grahpviz support is disabled since libgvc is not found") fi fi AM_CONDITIONAL(ENABLE_GVC, test x$enable_gvc = xyes) dnl ================== end of Graphviz checks ========================== Generated file: config.h /* Disable Graphviz support. */ #define ENABLE_GVC 1 3. Summary: echo " Configure summary: DBUS Support.......: $enable_dbus Nautilus Plugin....: $HAVE_NAUTILUS Thumbnailer........: $ENABLE_THUMBNAILER Gtk-Doc Support....: $enable_gtk_doc PDF Backend........: $enable_pdf PostScript Backend.: $enable_ps " It is useful when we check the configuration result. -------------------------------------------------------------------------------------------------------------------------------------------- June 26 让gnome-terminal进入指定目录的方法:1 点击鼠标右键,选择"properties"。 2 在"Command"编辑框输入: gnome-terminal --working-directory=你要进入的绝对目录 或者修改gnome-terminal.desktop文件(通常在你的home目录): Exec=gnome-terminal --working-directory=你要进入的绝对目录 June 25 Makefile Tips1. Makefile.am should include head source files (*.h, *.hh etc) . 2. A source directory without source can have some other files to distribute. The file Makefile.am in this directory can only have "EXTRA_DIST" field. 3. bootstrap: gettextize -f cd po intltool-update --pot mv xxx.pot en_GB.po # easy to forget cd .. autoreconf -fvi -Wall intltoolize -f -c --automake ./configure June 24 Tips1 C++ head file suffix should be "hh", souce file suffix should be "cc". 2. if ( !boost::filesystem::exists( "myfile.txt" ) ) { std::cout << "Can't find my file!" << std::endl; } 3. Read compilation error carefully and check if it is a link or load error. 4. Only apply polymorphism to polymorphic classes( virtual functions). 5. A data type is a set of values plus operations to work with them. 6. inline struct test{ int x; inline int get_x(){ std::cout<<"x: "<<x<<std::endl; return x; } }; 7. new void * new (const void * _class, ...) { const struct Class * class = _class; void * p = calloc(1, class —> size); assert(p); * (const struct Class **) p = class; if (class —> ctor) { va_list ap; va_start(ap, _class); p = class —> ctor(p, & ap); va_end(ap); } return p; } 8. std::getline(stream,line) -------------------------------------------------------------------------------------------------------------------------------------------- June 16 Media Independent Interface (MII)http://en.wikipedia.org/wiki/Media_Independent_Interface The Media Independent Interface (MII) is a standard interface used to connect a Fast Ethernet (i.e. 100Mb/s) MAC-block to a PHY. The MII may connect to an external transceiver device via a pluggable connector (see photo) or simply connect two chips on the same printed circuit board. Being media independent means that any of several different types of PHY devices can be used without redesigning or replacing the MAC hardware. The equivalents of MII for other speeds are AUI (for 10 megabit Ethernet), GMII (for gigabit Ethernet), and XAUI (for 10 gigabit Ethernet). To compile pango with cairo backend The documentation and configure file in pango does need improve. During in the configuration, there is a config error in config.log. It can be found around line 193xx and we could find a false condition of $freetype. So the solution is: 1. Install fontconfig newest version from: http://fontconfig.org/wiki/ 2. Install freetype newest version from: http://www.freetype.org/ After that, we can install pango, and then pangomm. June 03 acronymslist of acronyms in alphabetical order: * AFAICS = As far as I can see * BTW = By the way * FWIW = For what it's worth * FYI = For your information * HAND = Have a nice day * IMHO = In my humble opinion (egoless) * IMAO = In my arrogant opinion (oodles of ego) * IMNSHO = In my not-so humble opinion (a lot of ego) * IMO = In my opinion (not much ego) * KUTGW = Keep up the good work * MYOB = Mind your own business * OO = Object-oriented * OTOH = On the other hand * PEBCAC = Problem exists between chair and computer * PEBCAK = Problem exists between chair and keyboard * PMFJI = Pardon me for jumping in * RTFM = Read the ___ manual * SO = Significant other (as in, "My SO and I went for a walk...") * SSO = Small String Optimization (where short strings don't use the heap) * YHBT = You have been trolled * YHL = You have lost Gtk tips1. Glib::KeyFile Class This class lets you parse, edit or create files containing groups of key-value pairs, which we call key files for lack of a better name. http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1KeyFile.html#_details 2. Undo & Redo It needs 2 stacks: Undo stack and Redo Stack. 3. Recent file Glib::RefPtr<Gtk::Action> action = mp_action_group->get_action("ProjectRecent"); Glib::RefPtr<Gtk::RecentAction> recentAction = Glib::RefPtr<Gtk::RecentAction>::cast_static(action); Glib::RefPtr<Gtk::RecentInfo> cur = recentAction->get_current_item(); if(cur) { std::cout<<"Recent "<<cur->get_uri()<<std::endl; } 4. sigc::ptr_fun main_window.signal_unmap().connect(sigc::ptr_fun(&Gtk::Main::quit) ); 5. Gtk::AccelKey When we create acceleration key, we need add the acceleration group in the main window and indicate the window to accept keyboard messages. Window.add_events( Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::SCROLL_MASK | Gdk::POINTER_MOTION_MASK | Gdk::POINTER_MOTION_HINT_MASK ); Window.add_accel_group(->get_accel_group()); May 28 A complete example for sigc::signal<* * >/** * A complete example for sigc::signal<* * >. */ #include <syslog.h> #include <iostream> #include <vector> #include <deque> #include <queue> #include <list> #include <string> #include <algorithm> #include <iterator> #include <map> #include <memory> #include <boost/shared_ptr.hpp> #include <gtkmm.h> using namespace std; using namespace boost; class Document { }; class A{ private: sigc::signal<void, Document*> m_signal_document_create; public: A(){ /** * Just one example. The function signal_document_create can be called * lots of times. */ this->signal_document_create().connect (sigc::mem_fun(*this, &A::on_document_create)); } /** * This function is used and it provides a way for other class to build * signal connection many times. This structure is very flexible. */ sigc::signal<void, Document*>& signal_document_create(){ return m_signal_document_create; } void on_document_create(Document *doc){ /** ... */ } }; int main() { A a; return 1; } May 27 Gtk::manageFunction: template <class T> T* Gtk::manage ( T* obj ) [inline] Mark a Gtk::Object as owned by its parent container widget, so you don't need to delete it manually. For instance, Gtk::Button* button = Gtk::manage( new Gtk::Button("Hello") ); vbox.pack_start(*button); //vbox will delete button when vbox is deleted. Parameters: obj A Gtk::Object, such as a gtkmm widget. Returns: The Gtk::Object passed as the obj parameter. May 26 C++ Tips:1. modify linux version in: Makefile linux/utsrelease.h 2. export_symbol, module_init or module_exit exports symbols for different uses. 3. Gtk::ActionGroup mp_action_group->add( Gtk::RecentAction::create("ProjectRecent", "_Recent Projects"), sigc::mem_fun(*this, &galaxy::ui_manager::on_project_recent)); 4. Global variable: template <typename Dummy> class tlm_global_quantum { public: // // Returns a reference to the tlm_global_quantum singleton // static tlm_global_quantum& instance() { if (!m_instance) { m_instance = new tlm_global_quantum; } return *m_instance; } ......... } May 22 Gtk::StockIDhttp://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/namespaceGtk_1_1Stock.html#bf965c1d305e2880ac77f830477bb282 Glib::SListHandle<Gtk::StockID,Gtk::StockID_Traits> Gtk::Stock::get_ids ( ) ; typedef std::vector<Gtk::StockID> type_vecIDs; type_vecIDs vecIDs = Gtk::Stock::get_ids(); // iterate through them, populating the ListStore as appropriate for(type_vecIDs::const_iterator iterIDs = vecIDs.begin(); iterIDs != vecIDs.end(); ++iterIDs){ ... } May 20 C++ Tips1. C++ calls C function. When a C++ program calls a C function, we can use a declartion like: extern "C" c_function(); Please note we should not include the c_function associated file header. 2. std::stringstream std::stringstream ss( "33" ); ss >> (int_tst); std::stringstream text; text<<"( "<< i<< ", "<<j<<" )"; May 19 Bill Clinton, George W. Bush and George WashingtonBill Clinton, George W. Bush
and George Washington are on a sinking ship. As the boat sinks, George Washington heroically shouts, "Save the women!" George W. Bush hysterically hollers, "Screw the women!" Bill Clinton's asks excitedly, "Do we have time?" Home Theater PC (HTPC) or media PC A Home Theater PC (HTPC) or media PC is a convergence device that combines the functions of a personal computer and a media center software which feature video and music playback, and usually but not always also digital video recorder functionality. It usually has a 10-foot user interface and is connected to a television or a television-sized computer display, and is often used as a digital photo, music, video player, TV receiver and digital video recorder, and normally controlled with a remote control. The general goal of an HTPC is usually to combine many or all components of a home theater setup into one single box that will be located in the living room and is controlled with a remote control as the main interface, and the GUI normally has a 10-foot user interface design so that it can be comfortably viewed from a such distance. An HTPC can be purchased pre-configured with the required hardware and software needed to add television programming to the PC, or can be cobbled together out of discrete components as is commonly done with Windows Media Center, MediaPortal ,SageTV, MythTV, Freevo, or LinuxMCE. http://en.wikipedia.org/wiki/Htpc May 11 Two random uninterruptable processing logic:Scenario: Two events happen interchangably and any one of them can happen first. But if one event happens, it cannot be interrupted. Initialization: state: STATE_1ST and STATE_2ND not set. Procedure: if ( both STATE_1ST and STATE_2ND not set ) { if (STATE_1ST) { set STATE_1ST; } else { set STATE_2ND; } } if (STATE_1ST set) { do STATE_1ST; } else { do STATE_2ND; } Reset: state: STATE_1ST and STATE_2ND not set. End the University as We Know It |
|
||
|
|