#include #include #include #include "pandora.hpp" #define WNCK_I_KNOW_THIS_IS_UNSTABLE #include #include #include #include #include #include #include #include #include using namespace net::lliurex::lgi; using namespace net::lliurex::lgi::toolkit; using namespace std; bool quit_request=false; int mode = LGI_DISPATCH_EVENTS_FULL; int flow = 0; class FancyCursor: public BaseCursor { public: cairo_surface_t * pointer; FancyCursor() { pointer=cairo_image_surface_create_from_png("mice.png"); } void SetCursor(int type) { //nothing to do } void Draw(cairo_t * cairo) { cairo_set_source_surface(cairo,pointer,0.0,0.0); cairo_paint(cairo); } }; class ImageButton: public Widget { public: GdkPixbuf * pixbuf; ImageButton(const char * stockname,int x,int y) { this->x=x; this->y=y; this->name=string(stockname); this->mouse_over=false; this->mouse_press=false; pixbuf = gtk_icon_theme_load_icon( gtk_icon_theme_get_default(),stockname,64,GTK_ICON_LOOKUP_FORCE_SVG,NULL); this->width=64; this->height=64; } void Draw(cairo_t * cairo) { gdk_cairo_set_source_pixbuf(cairo,pixbuf,x,y); cairo_paint(cairo); if(mouse_over) { cairo_set_source_rgb(cairo,0.8f,0.0f,0.1f); cairo_set_line_width(cairo,2.0f); cairo_rectangle(cairo,x-2,y-2,width+4,height+5); cairo_stroke(cairo); } } void OnMouseMove(MouseMoveEvent * event) { //cout<<"moving "<x<<","<y<width<<"x"<height<text=lbl->text+string((char *)event->str); cout<<"str "<str<key==LGI_KEY_BACKSPACE) lbl->text=lbl->text.substr(0,lbl->text.size()-1); else lbl->text=lbl->text+string((char *)event->str); cout<<"str "<str<key<key==LGI_KEY_RIGHT)x=x+5.0f; if(event->key==LGI_KEY_LEFT)x=x-5.0f; } void OnKeyUp(KeyUpEvent * event) { cout<<"SandBox::KeyUp "<key<key<name<name=="Pandora::CheckBox") { ((pandora::CheckBox *)widget)->state=!((pandora::CheckBox *)widget)->state; } } } void OnMouseMove(Widget * widget,MouseMoveEvent * event) { if(widget!=NULL) { //cout<<"SandBox::MouseMove "<name<data,event->size); cout<<"uri:["<size<x<<","<y<xx; if(widgets[n]->yy; if((widgets[n]->x+widgets[n]->width)>maxx)maxx=widgets[n]->x+widgets[n]->width; if((widgets[n]->y+widgets[n]->height)>maxy)maxy=widgets[n]->y+widgets[n]->height; } cairo_set_source_rgba(cairo, 1.0, 0.8, 0.2, 0.5); cairo_rectangle(cairo,x+minx-5.0f,y+miny-5.0f,maxx-minx+10.0f,maxy-miny+10.0f); cairo_fill(cairo); //parent mmethod Layer::Draw(cairo); } }; class MenuBox : public Layer { private: ImageButton * btn1; ImageButton * btn2; ImageButton * btn3; public: MenuBox() : Layer("Menu") { btn1 = new ImageButton("gtk-home",5.0,5.0); btn2 = new ImageButton("application-exit",80.0,5.0); btn3 = new ImageButton("view-refresh",155.0,5.0); Add(btn1); Add(btn2); Add(btn3); } void OnMouseClick(Widget * widget,MouseClickEvent * event) { if(widget!=NULL) cout<<"MenuBox::Click "<name<name<SetCursorMode(LGI_CURSOR_MODE_CUSTOM); window->SetCustomCursor(&fancycursor); window->SetTitle("LGI Demo 3"); //window->SetSize(800,600); vector dnd_targets; dnd_targets.push_back(string("text/uri-list")); window->SetDndTargets(dnd_targets); //window.SetCursor(LGI_CURSOR_HAND); sandbox = new SandBox(); menubox = new MenuBox(); window->AddLayer(menubox); window->AddLayer(sandbox); gettimeofday(&last_time,NULL); wnck_screen_force_update(wnck_screen_get_default()); WnckWindow *xid=wnck_window_get(window->GetXWindow()); cout<<"Name: "<SetSize(800,600); int cx = (wnck_screen_get_width(wnck_screen_get_default())/2)-400; int cy = (wnck_screen_get_height(wnck_screen_get_default())/2)-300; wnck_window_set_geometry(xid,WNCK_WINDOW_GRAVITY_STATIC, (WnckWindowMoveResizeMask)(WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y | WNCK_WINDOW_CHANGE_WIDTH | WNCK_WINDOW_CHANGE_HEIGHT), cx,cy,1024,768); cout<<"Cx:"<DispatchEvents(mode); if(flow==1) { y+=dy; if(y<0.0f)dy=1.0f; if(y>480.0f)dy=-1.0f; } cairo = window->cairo; cairo_set_source_rgb(cairo,0.1,0.37,0.80); cairo_paint(cairo); cairo_set_source_rgb(cairo,0.5,0.5,0.9); cairo_arc(cairo,320.0,y,20.0,0.0,2.0*3.1416); cairo_fill(cairo); window->Flip(); fps++; gettimeofday(¤t_time,NULL); delta= (current_time.tv_sec - last_time.tv_sec)*1000 + (current_time.tv_usec - last_time.tv_usec)/1000.0; if(delta>=1000) { cout<Destroy(); delete window; return 0; }