[Jsmooth-cvs] jsmooth/skeletons/util-gui testmain.cpp, NONE, 1.1 Splash.h, NONE, 1.1 splashhelper.h
Status: Beta
Brought to you by:
reyes
Update of /cvsroot/jsmooth/jsmooth/skeletons/util-gui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10916/skeletons/util-gui Added Files: testmain.cpp Splash.h splashhelper.h guihelper.h splashhelper.cpp Makefile.win guihelper.cpp Splash.cpp Log Message: splash screen gui package --- NEW FILE: splashhelper.h --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __SPLASHHELPER_H_ #define __SPLASHHELPER_H_ #include <string> #include "windef.h" void splashwindow_start(const std::string& filename); bool splashwindow_isVisible(void); void splashwindow_hide(void); void splashwindow_setProgress(int cur, int max); void splashwindow_setProcessId(DWORD pid); #endif --- NEW FILE: Makefile.win --- # Project: CommonJava PROJECTNAME=util-gui RM = rm -f CPP = g++.exe CC = gcc.exe WINDRES = windres.exe MINGW = "c:/MinGW" FLTK-LDFLAGS = $(shell fltk-config --ldflags --use-images) FLTK-CXXFLAGS = $(shell fltk-config --cxxflags --use-images) RES = OBJ = guihelper.o splashhelper.o Splash.o $(RES) LIBS = -L"$(MINGW)/lib" -L"/lib" -lws2_32 -lwininet $(FLTK-LDFLAGS) CXXINCS = -Os -I"../util-core" -I"$(MINGW)/include/c++" -I"$(MINGW)/include/c++/mingw32" -I"$(MINGW)/include/c++/backward" -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" $(FLTK-CXXFLAGS) BIN = $(PROJECTNAME).a CXXFLAGS = $(CUSTOMFLAGS) $(CXXINCS) -DJDK="$(JDK)" .PHONY: all all-before all-after clean clean-custom $(PROJECTNAME) all: all-before $(PROJECTNAME).a testmain.cpp all-after clean: clean-custom $(RM) $(OBJ) $(BIN) test.exe testmain.o $(BIN): $(OBJ) ar r $(BIN) $(OBJ) ranlib $(BIN) $(CPP) -g testmain.o $(BIN) ../util-core/util-core.a -o test.exe $(LIBS) $(PROJECTNAME).a: $(OBJ) testmain.o testmain.o: testmain.cpp $(CPP) -c testmain.cpp -o testmain.o $(CXXFLAGS) --- NEW FILE: guihelper.h --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __GUIHELPER_H_ #define __GUIHELPER_H_ void guihelper_run(void); #endif --- NEW FILE: testmain.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <iostream> #include <stdlib.h> #include "StringUtils.h" #include "guihelper.h" #define DEBUG(x) _debugOutput(x) #define DEBUGWAITKEY() _debugWaitKey() void _debugOutput(const std::string& text) { // std::cerr << text << "\r\n"; printf("%s\n", text.c_str()); fflush(stdout); } void _debugWaitKey() { } int main(int argc, char *argv[]) { guihelper_run(); exit(0); } --- NEW FILE: Splash.h --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __SPLASH_H_ #define __SPLASH_H_ #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/Fl_Tile.H> #include <FL/Fl_Progress.H> #include <FL/Fl_Pack.H> #include <FL/Fl_Box.H> #include <FL/Fl_Group.H> #include <FL/Fl_Shared_Image.H> #include <FL/fl_draw.H> #include <FL/x.H> #include <string> #include "Thread.h" /** * Manages versions as used by Sun's JVM. The version scheme used is * major.minor.sub, for instance 1.1.8 or 1.4.2. * * @author Rodrigo Reyes <re...@ch...> */ class SplashContent : public Fl_Group { private: Fl_Shared_Image* m_splashImage; Fl_Progress* m_progressBar; std::string m_label; public: SplashContent(int x, int y, int w, int h, const char *label = 0, Fl_Shared_Image* image=0) : Fl_Group(x,y,w,h,label) { m_splashImage = image; buildGui(); } void buildGui(); void setProgress(int cur, int max); void setLabel(const std::string& label); virtual void draw(); }; class SplashWindow : public Fl_Double_Window { private: SplashContent* m_content; Fl_Shared_Image* m_splashImage; Thread* m_closer; DWORD m_watchedProcessId; static SplashWindow* s_singleton; public: SplashWindow(const std::string& splashfile); // Warning: NOT THREAD-SAFE static SplashWindow* getSingleton(); void setProgress(int cur, int max); void setLabel(const std::string& label); void splashCheck(HWND tocheck); void splashOn(); void splashOff(); void setWatchedProcessId(DWORD pid); DWORD getWatchedProcessId(); }; #endif --- NEW FILE: Splash.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "Splash.h" #include <stdio.h> #include "StringUtils.h" void SplashContent::buildGui() { m_progressBar = new Fl_Progress(x()+10,h()-20,w()-20,10); // redraw(); m_progressBar->hide(); } void SplashContent::setProgress(int cur, int max) { Fl::lock(); if (!m_progressBar->visible()) m_progressBar->show(); m_progressBar->maximum((float)max); m_progressBar->value((float)cur); m_progressBar->redraw(); Fl::awake(); Fl::unlock(); } void SplashContent::setLabel(const std::string& label) { Fl::lock(); m_label = label; if (m_label != "") { m_progressBar->position(x()+10, h()-32); m_progressBar->size(w()-20,22); } else { m_progressBar->position(x()+10, h()-20); m_progressBar->size(w()-20,10); } m_progressBar->label(m_label.c_str()); Fl::awake(); Fl::unlock(); } void SplashContent::draw() { fl_color(FL_BLACK); fl_rectf(0,0,w(),h()); if (m_splashImage != 0) { m_splashImage->draw(0,0); } Fl_Widget *const*a = array(); // now draw all the children atop the background: for (int i = children(); i --; a ++) { draw_child(**a); draw_outside_label(**a); // you may not need to do this } } SplashWindow::SplashWindow(const std::string& splashfile) : Fl_Double_Window(0,0) { if (s_singleton == 0) s_singleton = this; m_closer = new Thread(); m_watchedProcessId = 0; m_splashImage = Fl_Shared_Image::get(splashfile.c_str()); int w = 200, h = 200; if (m_splashImage != NULL) { w = m_splashImage->w(); h = m_splashImage->h(); printf("Splash window dimension: %dx%d\n", w,h); fflush(stdout); } size(w,h); border(0); position(Fl::w() / 2 - w/2, Fl::h() / 2 - h/2); m_content = new SplashContent(0,0, w, h, "splash", m_splashImage); end(); } BOOL CALLBACK thread_closer_enumerator(HWND hwnd, LPARAM param) { SplashWindow* splash = (SplashWindow*)param; DWORD hpid = 0; DWORD curpid = splash->getWatchedProcessId(); // GetCurrentProcessId(); GetWindowThreadProcessId(hwnd, &hpid); if (hpid == curpid) { if (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) { splash->splashCheck(hwnd); } } return TRUE; } void thread_closer(void* param) { SplashWindow* splash = (SplashWindow*)param; // int cur = 0; while (1) { Sleep(500); printf("Watching splash process %d\n", splash->getWatchedProcessId()); fflush(stdout); EnumWindows(thread_closer_enumerator, (LPARAM)splash); if (splash->visible() == 0) { return; } } } void SplashWindow::splashCheck(HWND tocheck) { if (tocheck != fl_xid(this)) { splashOff(); } } void SplashWindow::splashOn() { show(); m_closer->start(thread_closer, this); } void SplashWindow::splashOff() { Fl::lock(); hide(); Fl::unlock(); } void SplashWindow::setProgress(int cur, int max) { Fl::lock(); m_content->setProgress(cur, max); // Fl::redraw(); // Fl::awake(); Fl::unlock(); } void SplashWindow::setLabel(const std::string& label) { m_content->setLabel(label); } void SplashWindow::setWatchedProcessId(DWORD pid) { m_watchedProcessId = pid; } DWORD SplashWindow::getWatchedProcessId() { return m_watchedProcessId; } SplashWindow* SplashWindow::getSingleton() { return s_singleton; } SplashWindow* SplashWindow::s_singleton = 0; --- NEW FILE: splashhelper.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "splashhelper.h" #include "Splash.h" #include <FL/Fl_Shared_Image.H> #include <FL/Fl.H> #include "FileUtils.h" #include "guihelper.h" void splashwindow_start(const std::string& filename) { if (FileUtils::fileExists(filename)) { fl_register_images(); printf("Creating splash with image %s\n",filename.c_str()); fflush(stdout); SplashWindow* sw = new SplashWindow(filename); // SplashWindow::getSingleton()->splashOn(); guihelper_run(); } } bool splashwindow_isVisible() { SplashWindow* sp = SplashWindow::getSingleton(); if (sp != 0) return sp->visible(); } void splashwindow_hide() { SplashWindow* sp = SplashWindow::getSingleton(); if (sp != 0) sp->hide(); } void splashwindow_setProgress(int cur, int max) { SplashWindow* sp = SplashWindow::getSingleton(); if (sp != 0) sp->setProgress(cur, max); } void splashwindow_setProcessId(DWORD pid) { SplashWindow* sp = SplashWindow::getSingleton(); if (sp != 0) sp->setWatchedProcessId(pid); } --- NEW FILE: guihelper.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "guihelper.h" #include <FL/Fl.H> #include "Thread.h" #include "Splash.h" bool guihelper_running = false; void guihelper_run_thread(void* param) { if (guihelper_running == false) { guihelper_running = true; Fl::lock(); if (SplashWindow::getSingleton() != 0) SplashWindow::getSingleton()->splashOn(); Fl::run(); Fl::unlock(); } } void guihelper_run() { Thread* guithread = new Thread(); guithread->setAutoDelete(true); guithread->start(guihelper_run_thread, NULL); } |