Changeset 18
- Timestamp:
- 11/27/06 01:43:45 (2 years ago)
- Files:
-
- trunk/luigi/adaptor/base.d (modified) (10 diffs)
- trunk/luigi/adaptor/gld.d (added)
- trunk/luigi/adaptor/glfw.d (modified) (6 diffs)
- trunk/luigi/example1.d (modified) (5 diffs)
- trunk/luigi/example1_gld.brf (added)
- trunk/luigi/example1_gld.d (added)
- trunk/luigi/gui.d (modified) (5 diffs)
- trunk/luigi/themes/dxut.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/luigi/adaptor/base.d
r13 r18 3 3 Copyright: 4 4 5 luigi/adapt or/base.d -- input adaptor basics for the 'Luigi' user5 luigi/adapter/base.d -- input adaptor basics for the 'Luigi' user 6 6 interface library. 7 7 … … 26 26 William Baxter wbaxter@gmail.com 27 27 */ 28 module luigi.adapt or.base;28 module luigi.adapter.base; 29 29 30 30 //import sslot.signal; … … 34 34 35 35 36 /** The InputAdapt or interface allows the GUI to connect to various windowing toolkits.36 /** The InputAdapter interface allows the GUI to connect to various windowing toolkits. 37 37 Luigi wants to be able to get input from whatever source possible, be it GLFW, GLUT, SDL, 38 native Win32, GTK, wxWidgets, or whatever. Implementations of the input adapt or38 native Win32, GTK, wxWidgets, or whatever. Implementations of the input adapter 39 39 allow Luigi and applications to pretend that all toolkits work the same way, regardless 40 40 of the back-end chosen. In particular Luigi puts a facade of a Signals-and-Slots type … … 43 43 One common way simple toolkits like GLUT deliver input to applications is via callbacks. 44 44 They usually allow one, and only one, function to be called. 45 A concrete InputAdapt or for one of these will override all callback methods and emit45 A concrete InputAdapter for one of these will override all callback methods and emit 46 46 signals identifying all the events. 47 47 48 To implement a new adapt or, derive from the InputAdaptor interface, and mixin the49 InputAdapt orMix. This sets up the external interface and the signals.48 To implement a new adapter, derive from the InputAdapter interface, and mixin the 49 InputAdapterMix. This sets up the external interface and the signals. 50 50 Now all you have to do is 51 51 */ 52 interface InputAdapt or52 interface InputAdapter 53 53 { 54 54 // These are "raw" callbacks in that they haven't yet been translated or dispatched … … 80 80 81 81 // Other candidates: Create window, Move/Resize window, Set window title 82 // maybe need a separate WindowSys adapt or?82 // maybe need a separate WindowSys adapter? 83 83 // I don't want to be in the business of wrapping the OS, or becoming another GLUT. 84 84 // Just the minimal things needed to run an on-screen UI. Let them use GLUT for … … 87 87 } 88 88 89 template InputAdapt orMix()89 template InputAdapterMix() 90 90 { 91 91 //------------------------------------------------------- 92 // Use 'sig.*.emit' to emit signals from your InputAdapt or implementation.92 // Use 'sig.*.emit' to emit signals from your InputAdapter implementation. 93 93 // Use example: 94 94 // KeyEvent ev; … … 96 96 // sig.key.emit(ev); 97 97 98 // You MUST call this from your Adapt or's constructor!99 void initInputAdapt or() {98 // You MUST call this from your Adapter's constructor! 99 void initInputAdapter() { 100 100 with (_lsig) { 101 101 key = new KeyEventSignal; … … 109 109 110 110 //------------------------------------------------------- 111 // The rest shouldn't concernt InputAdapt or implementors111 // The rest shouldn't concernt InputAdapter implementors 112 112 private struct _LuigiSignals { 113 113 KeyEventSignal key; … … 121 121 alias _lsig sig; 122 122 123 // Implementation of InputAdapt or123 // Implementation of InputAdapter 124 124 void addKeyCallback(KeyEventFn cb) {_lsig.key.connect(cb);} 125 125 void addMouseButtonCallback(MouseButtonEventFn cb) {_lsig.mouseButton.connect(cb);} … … 143 143 /** Gather input from multiple places */ 144 144 /* 145 class CompoundInputAdapt or : InputAdaptor145 class CompoundInputAdapter : InputAdapter 146 146 { 147 InputAdapt or[] adaptors;147 InputAdapter[] adapters; 148 148 } 149 149 */ trunk/luigi/adaptor/glfw.d
r13 r18 3 3 Copyright: 4 4 5 luigi/adapt or/glfw.d6 -- GLFW input adapt or for the 'Luigi' user interface library.5 luigi/adapter/glfw.d 6 -- GLFW input adapter for the 'Luigi' user interface library. 7 7 8 8 Copyright (C) 2006 William V. Baxter III … … 26 26 William Baxter wbaxter@gmail.com 27 27 */ 28 module luigi.adapt or.glfw;28 module luigi.adapter.glfw; 29 29 30 30 import luigi.base; 31 31 import luigi.event; 32 import luigi.adapt or.base;32 import luigi.adapter.base; 33 33 import derelict.glfw.glfw; 34 34 //import sslot.signal; … … 110 110 111 111 112 class GLFWAdapt or : InputAdaptor112 class GLFWAdapter : InputAdapter 113 113 { 114 // Singleton access via static opCall GLFWAdapt or()115 static GLFWAdapt or opCall() {116 static GLFWAdapt or myinstance = null;114 // Singleton access via static opCall GLFWAdapter() 115 static GLFWAdapter opCall() { 116 static GLFWAdapter myinstance = null; 117 117 if (!myinstance) { 118 myinstance = new GLFWAdapt or;118 myinstance = new GLFWAdapter; 119 119 myinstance.init(); 120 120 } … … 122 122 } 123 123 // Singleton access via 'inst' property 124 static GLFWAdapt or inst() {125 return GLFWAdapt or();124 static GLFWAdapter inst() { 125 return GLFWAdapter(); 126 126 } 127 127 … … 270 270 // Singleton, so constructor is private 271 271 this() { 272 initInputAdapt or();272 initInputAdapter(); 273 273 } 274 274 void init() { … … 283 283 284 284 public: 285 mixin InputAdapt orMix;285 mixin InputAdapterMix; 286 286 287 287 } 288 288 289 289 290 alias GLFWAdapt or DefaultAdaptor;290 alias GLFWAdapter DefaultAdapter; trunk/luigi/example1.d
r15 r18 1 //---------------------------------------------------------------------2 1 /* 3 Copyright: 4 2 --------------------------------------------------------------------- 5 3 luigi/example1.d -- An example program using the Luigi user 6 4 interface library. 7 5 6 An example/test program for Luigi. 7 Uses the GLFW windowing toolkit via luigi.adapter.glfw. 8 --------------------------------------------------------------------- 8 9 Copyright (C) 2006 William V. Baxter III 9 10 … … 25 26 26 27 William Baxter wbaxter@gmail.com 28 29 --------------------------------------------------------------------- 30 Written in the D programming language (http://www.digitalmars.com/d) 31 --------------------------------------------------------------------- 27 32 */ 28 33 import luigui = luigi.gui; 29 import luigi.adapt or.glfw;34 import luigi.adapter.glfw; 30 35 static import luigi.themes.dxut; 31 36 … … 61 66 { 62 67 bool dosync = true; 68 char[] theme = "std"; 63 69 64 70 //---------------- PARSE ARGS ----------------------- 65 foreach( a; argv ) { 71 for( int i=1; i<argv.length; i++ ) { 72 auto a = argv[i]; 66 73 if (a == "-nosync") dosync = false; 67 74 else if (a == "-help") { usage(argv[0]); return; } 75 else if (a == "-theme") { 76 theme = argv[++i]; 77 } 68 78 } 69 79 … … 75 85 // Enable sticky keys 76 86 glfwEnable( GLFW_STICKY_KEYS ); 87 glfwEnable( GLFW_KEY_REPEAT ); 77 88 78 89 // Disable vertical sync if requested (on cards that support it) … … 87 98 luigui.Overlay gui; 88 99 with(luigui) { 89 Luigi().adaptor = GLFWAdaptor(); 90 Luigi().theme = new luigi.themes.dxut.DXUTTheme(); 100 Luigi().adapter = GLFWAdapter(); 101 if (theme == "dxut") { 102 Luigi().theme = new luigi.themes.dxut.DXUTTheme(); 103 } 91 104 gui = new Overlay; 92 105 trunk/luigi/gui.d
r17 r18 55 55 import luigi.theme; 56 56 import luigi.arranger; 57 import luigi.adapt or.base;57 import luigi.adapter.base; 58 58 //import sslot.signal; 59 59 import luigi.signalobj; 60 60 61 //import adapt or = luigi.adaptor.glfw;61 //import adapter = luigi.adapter.glfw; 62 62 63 63 import drawsys = luigi.gldraw; … … 75 75 /** 76 76 * The singleton master object. 77 * Holds GUI globals including the theme, the input adapt or, and keeps track77 * Holds GUI globals including the theme, the input adapter, and keeps track 78 78 * of all the top-level Frames and Overlays. 79 79 */ … … 97 97 98 98 if (!m_inputsys) { 99 throw new GUIException("Must set Luigi().adapt or before creating Overlays");99 throw new GUIException("Must set Luigi().adapter before creating Overlays"); 100 100 } 101 101 … … 115 115 } 116 116 117 void adapt or(InputAdaptor inputsys) {117 void adapter(InputAdapter inputsys) { 118 118 m_inputsys = inputsys; 119 119 } … … 130 130 131 131 Overlay[] m_guis; 132 InputAdapt or m_inputsys;132 InputAdapter m_inputsys; 133 133 Theme m_theme; 134 134 } trunk/luigi/themes/dxut.d
r17 r18 84 84 } 85 85 86 //---- ------------------------------------------------------------------86 //----THEME DATA-------------------------------------------------------- 87 87 class ThemeData { 88 // per-widget elements needed so we can blend objects independently 88 89 Element[] elements; 89 90 } … … 103 104 return get_theme_data(w).elements; 104 105 } 105 //---------------------------------------------------------------------- 106 106 107 //----GRPAHICS STATE------------------------------------------------------ 108 override void begin_drawing(Rect r) { 109 m_timer.stop(); 110 m_elapsedTime = m_timer.milliseconds / 1000.0; 111 m_timer.start(); 112 113 gldraw.push_graphics_state(r); 114 glPushAttrib(GL_TEXTURE_BIT); 115 116 glEnable(GL_BLEND); 117 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 118 glBindTexture(GL_TEXTURE_2D,m_texid); 119 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 120 121 glMatrixMode(GL_TEXTURE); 122 glPushMatrix(); 123 glLoadIdentity(); 124 glScalef(1./m_texw, 1./m_texh,1); 125 glMatrixMode(GL_MODELVIEW); 126 127 } 128 override void end_drawing() { 129 glPopAttrib(); // TEXTURE_BIT 130 gldraw.pop_graphics_state(); 131 glMatrixMode(GL_TEXTURE); 132 glPopMatrix(); 133 glMatrixMode(GL_MODELVIEW); 134 } 107 135 108 136 //============================================================================ 109 // Built-in Drawing and size routines137 // Widget drawing and size routines 110 138 111 139 //----HELPERS----------------------------------------------------------------- … … 142 170 } 143 171 144 //----GRPAHICS STATE------------------------------------------------------145 void begin_drawing(Rect r) {146 m_timer.stop();147 m_elapsedTime = m_timer.milliseconds / 1000.0;148 m_timer.start();149 150 gldraw.push_graphics_state(r);151 glPushAttrib(GL_TEXTURE_BIT);152 153 glEnable(GL_BLEND);154 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);155 glBindTexture(GL_TEXTURE_2D,m_texid);156 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);157 158 glMatrixMode(GL_TEXTURE);159 glPushMatrix();160 glLoadIdentity();161 glScalef(1./m_texw, 1./m_texh,1);162 glMatrixMode(GL_MODELVIEW);163 164 }165 void end_drawing() {166 glPopAttrib(); // TEXTURE_BIT167 gldraw.pop_graphics_state();168 glMatrixMode(GL_TEXTURE);169 glPopMatrix();170 glMatrixMode(GL_MODELVIEW);171 }172 172 //----LABEL--------------------------------------------------------------- 173 173 void label_register() { … … 180 180 Element e; 181 181 // button layer 182 e.set_texture( m_texid, [0,0,136,54] ); 182 183 e.fontColor.states[ WidgetState.Disabled ] = Color(200,200,200,200); 183 e.set_texture( m_texid, [0,0,136,54] );184 184 e.set_font( m_default_font ); 185 185 e.texColor.states[ WidgetState.Normal ] = Color(255, 255, 255, 150);
