| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <gdk/gdkx.h> |
|---|
| 5 | #include <gdk/gdkkeysyms.h> |
|---|
| 6 | #include <gtk/gtk.h> |
|---|
| 7 | #include <X11/keysym.h> |
|---|
| 8 | #include <sys/time.h> |
|---|
| 9 | #include "opengl.h" |
|---|
| 10 | #include "gtkmisc.h" |
|---|
| 11 | #include "lc_camera.h" |
|---|
| 12 | #include "project.h" |
|---|
| 13 | #include "system.h" |
|---|
| 14 | #include "main.h" |
|---|
| 15 | #include "toolbar.h" |
|---|
| 16 | #include "dialogs.h" |
|---|
| 17 | #include "globals.h" |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | int Sys_MessageBox (const char* text, const char* caption, int type) |
|---|
| 23 | { |
|---|
| 24 | return msgbox_execute (text, caption, type); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | typedef struct |
|---|
| 31 | { |
|---|
| 32 | int width, height; |
|---|
| 33 | Display *xdisplay; |
|---|
| 34 | GLXPixmap glxpixmap; |
|---|
| 35 | GLXContext glxcontext; |
|---|
| 36 | GdkPixmap *pixmap; |
|---|
| 37 | GdkVisual *visual; |
|---|
| 38 | } LC_RENDER; |
|---|
| 39 | |
|---|
| 40 | void* Sys_StartMemoryRender(int width, int height) |
|---|
| 41 | { |
|---|
| 42 | LC_RENDER* render = (LC_RENDER*) malloc (sizeof (LC_RENDER)); |
|---|
| 43 | int attrlist[] = { GLX_RGBA, GLX_DEPTH_SIZE, 16, 0 }; |
|---|
| 44 | XVisualInfo *vi; |
|---|
| 45 | Pixmap xpixmap; |
|---|
| 46 | |
|---|
| 47 | render->width = width; |
|---|
| 48 | render->height = height; |
|---|
| 49 | render->xdisplay = GDK_DISPLAY(); |
|---|
| 50 | |
|---|
| 51 | vi = pfnglXChooseVisual (render->xdisplay, DefaultScreen (render->xdisplay), attrlist); |
|---|
| 52 | |
|---|
| 53 | render->visual = gdkx_visual_get (vi->visualid); |
|---|
| 54 | render->glxcontext = pfnglXCreateContext (render->xdisplay, vi, NULL, True); |
|---|
| 55 | render->pixmap = gdk_pixmap_new (NULL, width, height, render->visual->depth); |
|---|
| 56 | |
|---|
| 57 | xpixmap = (Pixmap)GDK_DRAWABLE_XID(render->pixmap); |
|---|
| 58 | render->glxpixmap = pfnglXCreateGLXPixmap (render->xdisplay, vi, xpixmap); |
|---|
| 59 | |
|---|
| 60 | XFree(vi); |
|---|
| 61 | |
|---|
| 62 | pfnglXMakeCurrent (render->xdisplay, render->glxpixmap, render->glxcontext); |
|---|
| 63 | |
|---|
| 64 | return render; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void Sys_FinishMemoryRender(void* param) |
|---|
| 68 | { |
|---|
| 69 | LC_RENDER* render = (LC_RENDER*)param; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | if (render->glxcontext == pfnglXGetCurrentContext ()) |
|---|
| 74 | pfnglXMakeCurrent (render->xdisplay, None, NULL); |
|---|
| 75 | pfnglXDestroyContext (render->xdisplay, render->glxcontext); |
|---|
| 76 | |
|---|
| 77 | pfnglXDestroyGLXPixmap (render->xdisplay, render->glxpixmap); |
|---|
| 78 | pfnglXWaitGL(); |
|---|
| 79 | gdk_pixmap_unref (render->pixmap); |
|---|
| 80 | pfnglXWaitX(); |
|---|
| 81 | free(render); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | bool Sys_KeyDown (int key) |
|---|
| 89 | { |
|---|
| 90 | char keys[32]; |
|---|
| 91 | int x; |
|---|
| 92 | |
|---|
| 93 | XQueryKeymap (GDK_DISPLAY (), keys); |
|---|
| 94 | |
|---|
| 95 | x = XKeysymToKeycode (GDK_DISPLAY (), XK_Control_L); |
|---|
| 96 | if (keys[x/8] & (1 << (x % 8))) |
|---|
| 97 | return true; |
|---|
| 98 | |
|---|
| 99 | x = XKeysymToKeycode (GDK_DISPLAY (), XK_Control_R); |
|---|
| 100 | if (keys[x/8] & (1 << (x % 8))) |
|---|
| 101 | return true; |
|---|
| 102 | |
|---|
| 103 | return false; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | char* strupr(char* string) |
|---|
| 112 | { |
|---|
| 113 | char *cp; |
|---|
| 114 | for (cp=string; *cp; ++cp) |
|---|
| 115 | { |
|---|
| 116 | if ('a' <= *cp && *cp <= 'z') |
|---|
| 117 | *cp += 'A' - 'a'; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | return string; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | char* strlwr(char* string) |
|---|
| 124 | { |
|---|
| 125 | char *cp; |
|---|
| 126 | for (cp = string; *cp; ++cp) |
|---|
| 127 | { |
|---|
| 128 | if ('A' <= *cp && *cp <= 'Z') |
|---|
| 129 | *cp += 'a' - 'A'; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | return string; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | int stricmp(const char* str1, const char* str2) |
|---|
| 136 | { |
|---|
| 137 | return g_ascii_strcasecmp(str1, str2); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | void SystemPumpMessages() |
|---|
| 144 | { |
|---|
| 145 | while (gtk_events_pending ()) |
|---|
| 146 | gtk_main_iteration (); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | long SystemGetTicks() |
|---|
| 150 | { |
|---|
| 151 | static int basetime = 0; |
|---|
| 152 | struct timezone tzp; |
|---|
| 153 | struct timeval tp; |
|---|
| 154 | |
|---|
| 155 | gettimeofday (&tp, &tzp); |
|---|
| 156 | |
|---|
| 157 | if (!basetime) |
|---|
| 158 | basetime = tp.tv_sec; |
|---|
| 159 | |
|---|
| 160 | return (tp.tv_sec-basetime)*1000 + tp.tv_usec/1000; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | void SystemUpdateCategories(bool SearchOnly) |
|---|
| 165 | { |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | static void create_bitmap_and_mask_from_xpm (GdkBitmap** bitmap, GdkBitmap** mask, const char** xpm) |
|---|
| 169 | { |
|---|
| 170 | int height, width, colors; |
|---|
| 171 | char pixmap_buffer [(32 * 32)/8]; |
|---|
| 172 | char mask_buffer [(32 * 32)/8]; |
|---|
| 173 | int x, y, pix; |
|---|
| 174 | int transparent_color, black_color; |
|---|
| 175 | |
|---|
| 176 | sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix); |
|---|
| 177 | |
|---|
| 178 | g_assert (height == 32); |
|---|
| 179 | g_assert (width == 32); |
|---|
| 180 | g_assert (colors == 3); |
|---|
| 181 | |
|---|
| 182 | transparent_color = ' '; |
|---|
| 183 | black_color = '.'; |
|---|
| 184 | |
|---|
| 185 | for (y = 0; y < 32; y++) |
|---|
| 186 | for (x = 0; x < 32;) |
|---|
| 187 | { |
|---|
| 188 | char value = 0, maskv = 0; |
|---|
| 189 | |
|---|
| 190 | for (pix = 0; pix < 8; pix++, x++) |
|---|
| 191 | if (xpm [4+y][x] != transparent_color) |
|---|
| 192 | { |
|---|
| 193 | maskv |= 1 << pix; |
|---|
| 194 | |
|---|
| 195 | if (xpm [4+y][x] != black_color) |
|---|
| 196 | value |= 1 << pix; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | pixmap_buffer [(y * 4 + x/8)-1] = value; |
|---|
| 200 | mask_buffer [(y * 4 + x/8)-1] = maskv; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | *bitmap = gdk_bitmap_create_from_data (NULL, pixmap_buffer, 32, 32); |
|---|
| 204 | *mask = gdk_bitmap_create_from_data (NULL, mask_buffer, 32, 32); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | void SystemUpdateAction(int new_action, int old_action) |
|---|
| 208 | { |
|---|
| 209 | #include "pixmaps/cr_brick.xpm" |
|---|
| 210 | #include "pixmaps/cr_light.xpm" |
|---|
| 211 | #include "pixmaps/cr_spot.xpm" |
|---|
| 212 | #include "pixmaps/cr_cam.xpm" |
|---|
| 213 | #include "pixmaps/cr_sel.xpm" |
|---|
| 214 | #include "pixmaps/cr_selm.xpm" |
|---|
| 215 | #include "pixmaps/cr_move.xpm" |
|---|
| 216 | #include "pixmaps/cr_rot.xpm" |
|---|
| 217 | #include "pixmaps/cr_paint.xpm" |
|---|
| 218 | #include "pixmaps/cr_erase.xpm" |
|---|
| 219 | #include "pixmaps/cr_pan.xpm" |
|---|
| 220 | #include "pixmaps/cr_rotv.xpm" |
|---|
| 221 | #include "pixmaps/cr_roll.xpm" |
|---|
| 222 | #include "pixmaps/cr_zoom.xpm" |
|---|
| 223 | #include "pixmaps/cr_zoomr.xpm" |
|---|
| 224 | |
|---|
| 225 | if (!drawing_area) |
|---|
| 226 | return; |
|---|
| 227 | |
|---|
| 228 | GtkWidget* button; |
|---|
| 229 | const char** xpm = NULL; |
|---|
| 230 | int x, y; |
|---|
| 231 | |
|---|
| 232 | switch (new_action) |
|---|
| 233 | { |
|---|
| 234 | case LC_ACTION_SELECT: button = tool_toolbar.select; |
|---|
| 235 | { |
|---|
| 236 | x = 0; y = 2; |
|---|
| 237 | |
|---|
| 238 | if (Sys_KeyDown (KEY_CONTROL)) |
|---|
| 239 | xpm = cr_selm; |
|---|
| 240 | else |
|---|
| 241 | xpm = cr_sel; |
|---|
| 242 | } break; |
|---|
| 243 | case LC_ACTION_INSERT: |
|---|
| 244 | button = tool_toolbar.brick; xpm = cr_brick; x = 8; y = 3; break; |
|---|
| 245 | case LC_ACTION_LIGHT: |
|---|
| 246 | button = tool_toolbar.light; xpm = cr_light; x = 15; y = 15; break; |
|---|
| 247 | case LC_ACTION_SPOTLIGHT: |
|---|
| 248 | button = tool_toolbar.spot; xpm = cr_spot; x = 7; y = 10; break; |
|---|
| 249 | case LC_ACTION_CAMERA: |
|---|
| 250 | button = tool_toolbar.camera; xpm = cr_cam; x = 15; y = 9; break; |
|---|
| 251 | case LC_ACTION_MOVE: |
|---|
| 252 | button = tool_toolbar.move; xpm = cr_move; x = 15; y = 15; break; |
|---|
| 253 | case LC_ACTION_ROTATE: |
|---|
| 254 | button = tool_toolbar.rotate; xpm = cr_rot; x = 15; y = 15; break; |
|---|
| 255 | case LC_ACTION_ERASER: |
|---|
| 256 | button = tool_toolbar.erase; xpm = cr_erase; x = 0; y = 10; break; |
|---|
| 257 | case LC_ACTION_PAINT: |
|---|
| 258 | button = tool_toolbar.paint; xpm = cr_paint; x = 14; y = 14; break; |
|---|
| 259 | case LC_ACTION_ZOOM: |
|---|
| 260 | button = tool_toolbar.zoom; xpm = cr_zoom; x = 15; y = 15; break; |
|---|
| 261 | case LC_ACTION_ZOOM_REGION: |
|---|
| 262 | button = tool_toolbar.zoomreg; xpm = cr_zoomr; x = 9; y = 9; break; |
|---|
| 263 | case LC_ACTION_PAN: |
|---|
| 264 | button = tool_toolbar.pan; xpm = cr_pan; x = 15; y = 15; break; |
|---|
| 265 | case LC_ACTION_ROTATE_VIEW: |
|---|
| 266 | button = tool_toolbar.rotview; xpm = cr_rotv; x = 15; y = 15; break; |
|---|
| 267 | case LC_ACTION_ROLL: |
|---|
| 268 | button = tool_toolbar.roll; xpm = cr_roll; x = 15; y = 15; break; |
|---|
| 269 | default: |
|---|
| 270 | return; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | GdkBitmap *bitmap; |
|---|
| 274 | GdkBitmap *mask; |
|---|
| 275 | GdkCursor *cursor; |
|---|
| 276 | GdkColor white = {0, 0xffff, 0xffff, 0xffff}; |
|---|
| 277 | GdkColor black = {0, 0x0000, 0x0000, 0x0000}; |
|---|
| 278 | |
|---|
| 279 | if (xpm != NULL) |
|---|
| 280 | { |
|---|
| 281 | create_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm); |
|---|
| 282 | cursor = gdk_cursor_new_from_pixmap (bitmap, mask, &white, &black, x, y); |
|---|
| 283 | gdk_window_set_cursor (drawing_area->window, cursor); |
|---|
| 284 | } |
|---|
| 285 | else |
|---|
| 286 | { |
|---|
| 287 | cursor = gdk_cursor_new (GDK_LEFT_PTR); |
|---|
| 288 | gdk_window_set_cursor (drawing_area->window, cursor); |
|---|
| 289 | gdk_cursor_destroy (cursor); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | ignore_commands = true; |
|---|
| 293 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
|---|
| 294 | ignore_commands = false; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | void SystemUpdateColorList(int new_color) |
|---|
| 298 | { |
|---|
| 299 | colorlist_set(new_color); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | void SystemUpdateRenderingMode(bool bBackground, bool bFast) |
|---|
| 303 | { |
|---|
| 304 | if (!main_toolbar.fast) |
|---|
| 305 | return; |
|---|
| 306 | |
|---|
| 307 | ignore_commands = true; |
|---|
| 308 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(main_toolbar.fast), bFast); |
|---|
| 309 | ignore_commands = false; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | void SystemUpdateUndoRedo(char* undo, char* redo) |
|---|
| 313 | { |
|---|
| 314 | gpointer item; |
|---|
| 315 | char text[50]; |
|---|
| 316 | |
|---|
| 317 | strcpy(text, "Undo "); |
|---|
| 318 | if (undo) |
|---|
| 319 | strcat(text, undo); |
|---|
| 320 | item = gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_undo"); |
|---|
| 321 | |
|---|
| 322 | if (!item) |
|---|
| 323 | return; |
|---|
| 324 | |
|---|
| 325 | gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), text); |
|---|
| 326 | gtk_widget_set_sensitive (GTK_WIDGET (item), undo != NULL); |
|---|
| 327 | |
|---|
| 328 | strcpy(text, "Redo "); |
|---|
| 329 | if (redo) |
|---|
| 330 | strcat(text, redo); |
|---|
| 331 | item = gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_redo"); |
|---|
| 332 | gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), text); |
|---|
| 333 | gtk_widget_set_sensitive (GTK_WIDGET (item), redo != NULL); |
|---|
| 334 | |
|---|
| 335 | gtk_widget_set_sensitive (main_toolbar.undo, undo != NULL); |
|---|
| 336 | gtk_widget_set_sensitive (main_toolbar.redo, redo != NULL); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | void SystemUpdateSnap(const unsigned long snap) |
|---|
| 340 | { |
|---|
| 341 | if (!main_toolbar.angle) |
|---|
| 342 | return; |
|---|
| 343 | |
|---|
| 344 | ignore_commands = true; |
|---|
| 345 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(main_toolbar.angle), (snap & LC_DRAW_SNAP_A) != 0); |
|---|
| 346 | ignore_commands = false; |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | void SystemUpdateCurrentCamera(lcObject* pOld, lcObject* pNew, lcObject* pCamera) |
|---|
| 352 | { |
|---|
| 353 | gpointer item = NULL; |
|---|
| 354 | gpointer menu = gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "cameras_menu"); |
|---|
| 355 | |
|---|
| 356 | if (!menu) |
|---|
| 357 | return; |
|---|
| 358 | |
|---|
| 359 | GList *lst = gtk_container_children (GTK_CONTAINER (menu)); |
|---|
| 360 | |
|---|
| 361 | for (int i = 0; pCamera; i++, pCamera = (lcCamera*)pCamera->m_Next) |
|---|
| 362 | if (pNew == pCamera) |
|---|
| 363 | { |
|---|
| 364 | if (i >= 7) |
|---|
| 365 | item = g_list_nth_data (lst, i-7); |
|---|
| 366 | else |
|---|
| 367 | { |
|---|
| 368 | guint len = g_list_length (lst); |
|---|
| 369 | |
|---|
| 370 | if (len > 7) |
|---|
| 371 | item = g_list_nth_data (lst, len - 7 + i); |
|---|
| 372 | else |
|---|
| 373 | item = g_list_nth_data (lst, i); |
|---|
| 374 | } |
|---|
| 375 | break; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | if (item) |
|---|
| 379 | { |
|---|
| 380 | ignore_commands = true; |
|---|
| 381 | gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM (item), TRUE); |
|---|
| 382 | ignore_commands = false; |
|---|
| 383 | } |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | void SystemUpdateModelMenu(const lcPtrArray<lcModel>& ModelList, lcModel* CurrentModel) |
|---|
| 387 | { |
|---|
| 388 | |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | void SystemUpdateCameraMenu(lcObject* pCamera) |
|---|
| 392 | { |
|---|
| 393 | GtkWidget *menu = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "cameras_menu")); |
|---|
| 394 | GtkWidget *item = NULL; |
|---|
| 395 | lcObject* pFirst = pCamera; |
|---|
| 396 | GList *lst; |
|---|
| 397 | int i; |
|---|
| 398 | |
|---|
| 399 | if (!menu) |
|---|
| 400 | return; |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | while ((lst = gtk_container_children (GTK_CONTAINER (menu))) != NULL) |
|---|
| 404 | gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (lst->data)); |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | for (i = 0; pCamera; i++, pCamera = (lcCamera*)pCamera->m_Next) |
|---|
| 408 | if (i > 6) |
|---|
| 409 | { |
|---|
| 410 | GSList* grp = item ? gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (item)) : NULL; |
|---|
| 411 | item = gtk_radio_menu_item_new_with_label(grp, (const char*)pCamera->m_Name); |
|---|
| 412 | gtk_menu_append (GTK_MENU (menu), item); |
|---|
| 413 | gtk_widget_show (item); |
|---|
| 414 | gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (OnCommand), |
|---|
| 415 | GINT_TO_POINTER (i + ID_CAMERA_FIRST)); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | if (i > 7) |
|---|
| 419 | menu_separator (menu); |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | for (pCamera = pFirst, i = 0; pCamera && (i < 7); i++, pCamera = (lcCamera*)pCamera->m_Next) |
|---|
| 423 | { |
|---|
| 424 | GSList* grp = item ? gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (item)) : NULL; |
|---|
| 425 | item = gtk_radio_menu_item_new_with_label (grp, (const char*)pCamera->m_Name); |
|---|
| 426 | gtk_menu_append (GTK_MENU (menu), item); |
|---|
| 427 | gtk_widget_show (item); |
|---|
| 428 | gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (OnCommand), |
|---|
| 429 | GINT_TO_POINTER (i + ID_CAMERA_FIRST)); |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | void SystemUpdateTime(bool bAnimation, int nTime, int nTotal) |
|---|
| 434 | { |
|---|
| 435 | GtkWidget *item; |
|---|
| 436 | |
|---|
| 437 | if (!anim_toolbar.first) |
|---|
| 438 | return; |
|---|
| 439 | |
|---|
| 440 | gtk_widget_set_sensitive (anim_toolbar.first, nTime != 1); |
|---|
| 441 | gtk_widget_set_sensitive (anim_toolbar.prev, nTime > 1); |
|---|
| 442 | gtk_widget_set_sensitive (anim_toolbar.next, nTime < nTotal); |
|---|
| 443 | gtk_widget_set_sensitive (anim_toolbar.last, nTime != nTotal); |
|---|
| 444 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_view_step_first")); |
|---|
| 445 | gtk_widget_set_sensitive (item, nTime != 1); |
|---|
| 446 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_view_step_previous")); |
|---|
| 447 | gtk_widget_set_sensitive (item, nTime > 1); |
|---|
| 448 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_view_step_next")); |
|---|
| 449 | gtk_widget_set_sensitive (item, nTime < nTotal); |
|---|
| 450 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_view_step_last")); |
|---|
| 451 | gtk_widget_set_sensitive (item, nTime != nTotal); |
|---|
| 452 | |
|---|
| 453 | char text[11]; |
|---|
| 454 | if (bAnimation) |
|---|
| 455 | sprintf(text, "%i/%i", nTime, nTotal); |
|---|
| 456 | else |
|---|
| 457 | sprintf(text, " Step %i ", nTime); |
|---|
| 458 | gtk_label_set (GTK_LABEL (label_step), text); |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | void SystemUpdateAnimation(bool bAnimation, bool bAddKeys) |
|---|
| 464 | { |
|---|
| 465 | if (!anim_toolbar.play) |
|---|
| 466 | return; |
|---|
| 467 | |
|---|
| 468 | ignore_commands = true; |
|---|
| 469 | gtk_widget_set_sensitive (anim_toolbar.play, bAnimation); |
|---|
| 470 | gtk_widget_set_sensitive (anim_toolbar.stop, FALSE); |
|---|
| 471 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(anim_toolbar.anim), bAnimation); |
|---|
| 472 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(anim_toolbar.keys), bAddKeys); |
|---|
| 473 | ignore_commands = false; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | void SystemUpdateSnap(unsigned short move_snap, unsigned short RotateSnap) |
|---|
| 477 | { |
|---|
| 478 | if (!label_snap) |
|---|
| 479 | return; |
|---|
| 480 | |
|---|
| 481 | char text[11]; |
|---|
| 482 | if (move_snap) |
|---|
| 483 | sprintf (text, "Move x%i", move_snap); |
|---|
| 484 | else |
|---|
| 485 | strcpy (text, "Move /2"); |
|---|
| 486 | |
|---|
| 487 | gtk_label_set (GTK_LABEL (label_snap), text); |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | void SystemUpdateSelected(unsigned long flags, int SelectedCount, lcObject* Focus) |
|---|
| 491 | { |
|---|
| 492 | GtkWidget *item; |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_select_all")); |
|---|
| 496 | |
|---|
| 497 | if (!item) |
|---|
| 498 | return; |
|---|
| 499 | |
|---|
| 500 | gtk_widget_set_sensitive (item, (flags & LC_SEL_UNSELECTED) != 0); |
|---|
| 501 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_select_none")); |
|---|
| 502 | gtk_widget_set_sensitive (item, flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT) != 0); |
|---|
| 503 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_select_invert")); |
|---|
| 504 | gtk_widget_set_sensitive (item, (flags & LC_SEL_NO_PIECES) == 0); |
|---|
| 505 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_select_byname")); |
|---|
| 506 | gtk_widget_set_sensitive (item, (flags & LC_SEL_NO_PIECES) == 0); |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_cut")); |
|---|
| 510 | gtk_widget_set_sensitive (item, (flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT)) != 0); |
|---|
| 511 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_copy")); |
|---|
| 512 | gtk_widget_set_sensitive (item, (flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT)) != 0); |
|---|
| 513 | gtk_widget_set_sensitive (main_toolbar.cut, (flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT)) != 0); |
|---|
| 514 | gtk_widget_set_sensitive (main_toolbar.copy, (flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT)) != 0); |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_delete")); |
|---|
| 518 | gtk_widget_set_sensitive (item, (flags & (LC_SEL_PIECE|LC_SEL_CAMERA|LC_SEL_LIGHT)) != 0); |
|---|
| 519 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_array")); |
|---|
| 520 | gtk_widget_set_sensitive (item, (flags & LC_SEL_PIECE) != 0); |
|---|
| 521 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_hide_selected")); |
|---|
| 522 | gtk_widget_set_sensitive (item, (flags & LC_SEL_PIECE) != 0); |
|---|
| 523 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_hide_unselected")); |
|---|
| 524 | gtk_widget_set_sensitive (item, (flags & LC_SEL_UNSELECTED) != 0); |
|---|
| 525 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_unhide_all")); |
|---|
| 526 | gtk_widget_set_sensitive (item, (flags & LC_SEL_HIDDEN) != 0); |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_group")); |
|---|
| 530 | gtk_widget_set_sensitive (item, (flags & LC_SEL_CANGROUP) != 0); |
|---|
| 531 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_ungroup")); |
|---|
| 532 | gtk_widget_set_sensitive (item, (flags & LC_SEL_GROUP) != 0); |
|---|
| 533 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_group_add")); |
|---|
| 534 | gtk_widget_set_sensitive (item, (flags & (LC_SEL_GROUP|LC_SEL_FOCUSGROUP)) == LC_SEL_GROUP); |
|---|
| 535 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_group_remove")); |
|---|
| 536 | gtk_widget_set_sensitive (item, (flags & LC_SEL_FOCUSGROUP) != 0); |
|---|
| 537 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_piece_group_edit")); |
|---|
| 538 | gtk_widget_set_sensitive (item, (flags & LC_SEL_NO_PIECES) == 0); |
|---|
| 539 | |
|---|
| 540 | gtk_widget_set_sensitive (tool_toolbar.prev, (flags & LC_SEL_PIECE) != 0); |
|---|
| 541 | gtk_widget_set_sensitive (tool_toolbar.next, (flags & LC_SEL_PIECE) != 0); |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | void SystemUpdateRecentMenu (String names[4]) |
|---|
| 545 | { |
|---|
| 546 | GtkWidget *item; |
|---|
| 547 | char buf[32]; |
|---|
| 548 | |
|---|
| 549 | for (int i = 0; i < 4; i++) |
|---|
| 550 | { |
|---|
| 551 | sprintf (buf, "menu_file_recent%d", i+1); |
|---|
| 552 | item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), buf)); |
|---|
| 553 | |
|---|
| 554 | if (!names[i].IsEmpty ()) |
|---|
| 555 | { |
|---|
| 556 | if (i == 0) |
|---|
| 557 | { |
|---|
| 558 | gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), "Recent Files"); |
|---|
| 559 | gtk_widget_set_sensitive (item, FALSE); |
|---|
| 560 | } |
|---|
| 561 | else |
|---|
| 562 | gtk_widget_hide (item); |
|---|
| 563 | } |
|---|
| 564 | else |
|---|
| 565 | { |
|---|
| 566 | char text[LC_MAXPATH+4]; |
|---|
| 567 | |
|---|
| 568 | sprintf (text, "_%d- %s", i+1, (char*)names[i]); |
|---|
| 569 | gtk_label_set_text_with_mnemonic(GTK_LABEL(GTK_BIN(item)->child), text); |
|---|
| 570 | gtk_widget_show(item); |
|---|
| 571 | gtk_widget_set_sensitive(item, TRUE); |
|---|
| 572 | } |
|---|
| 573 | } |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | void SystemUpdatePaste(bool enable) |
|---|
| 577 | { |
|---|
| 578 | gtk_widget_set_sensitive (main_toolbar.paste, enable); |
|---|
| 579 | GtkWidget *item = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (((GtkWidget*)(*main_window))), "menu_edit_paste")); |
|---|
| 580 | gtk_widget_set_sensitive (item, enable); |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | void SystemUpdatePlay(bool play, bool stop) |
|---|
| 584 | { |
|---|
| 585 | gtk_widget_set_sensitive (anim_toolbar.play, play); |
|---|
| 586 | gtk_widget_set_sensitive (anim_toolbar.stop, stop); |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | void SystemInit() |
|---|
| 590 | { |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | void SystemFinish() |
|---|
| 594 | { |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | int SystemDoMessageBox(const char* prompt, int mode) |
|---|
| 599 | { |
|---|
| 600 | return msgbox_execute (prompt, "LeoCAD", mode); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | bool SystemDoDialog(int mode, void* param) |
|---|
| 604 | { |
|---|
| 605 | switch (mode) |
|---|
| 606 | { |
|---|
| 607 | case LC_DLG_FILE_OPEN_PROJECT: { |
|---|
| 608 | return openprojectdlg_execute ((char*)param) == LC_OK; |
|---|
| 609 | } break; |
|---|
| 610 | |
|---|
| 611 | case LC_DLG_FILE_SAVE_PROJECT: { |
|---|
| 612 | return saveprojectdlg_execute ((char*)param) == LC_OK; |
|---|
| 613 | } break; |
|---|
| 614 | |
|---|
| 615 | case LC_DLG_FILE_MERGE_PROJECT: { |
|---|
| 616 | return openprojectdlg_execute ((char*)param) == LC_OK; |
|---|
| 617 | } break; |
|---|
| 618 | |
|---|
| 619 | case LC_DLG_DIRECTORY_BROWSE: { |
|---|
| 620 | return dirbrowsedlg_execute(param) == LC_OK; |
|---|
| 621 | } break; |
|---|
| 622 | |
|---|
| 623 | case LC_DLG_ABOUT: { |
|---|
| 624 | return aboutdlg_execute(param) == LC_OK; |
|---|
| 625 | } break; |
|---|
| 626 | |
|---|
| 627 | case LC_DLG_ARRAY: { |
|---|
| 628 | return arraydlg_execute(param) == LC_OK; |
|---|
| 629 | } break; |
|---|
| 630 | |
|---|
| 631 | case LC_DLG_HTML: { |
|---|
| 632 | return htmldlg_execute(param) == LC_OK; |
|---|
| 633 | } break; |
|---|
| 634 | |
|---|
| 635 | case LC_DLG_POVRAY: { |
|---|
| 636 | return povraydlg_execute(param) == LC_OK; |
|---|
| 637 | } break; |
|---|
| 638 | |
|---|
| 639 | case LC_DLG_WAVEFRONT: { |
|---|
| 640 | return filedlg_execute("Save File", (char*)param) == LC_OK; |
|---|
| 641 | } break; |
|---|
| 642 | |
|---|
| 643 | case LC_DLG_VRML97: { |
|---|
| 644 | return filedlg_execute("Save File", (char*)param) == LC_OK; |
|---|
| 645 | } break; |
|---|
| 646 | |
|---|
| 647 | case LC_DLG_X3DV: { |
|---|
| 648 | return filedlg_execute("Save File", (char*)param) == LC_OK; |
|---|
| 649 | } break; |
|---|
| 650 | |
|---|
| 651 | case LC_DLG_PREFERENCES: { |
|---|
| 652 | return preferencesdlg_execute(param) == LC_OK; |
|---|
| 653 | } break; |
|---|
| 654 | |
|---|
| 655 | case LC_DLG_PICTURE_SAVE: { |
|---|
| 656 | return savepicturedlg_execute (param) == LC_OK; |
|---|
| 657 | } break; |
|---|
| 658 | |
|---|
| 659 | case LC_DLG_MINIFIG: { |
|---|
| 660 | return minifigdlg_execute(param) == LC_OK; |
|---|
| 661 | } break; |
|---|
| 662 | |
|---|
| 663 | case LC_DLG_PROPERTIES: { |
|---|
| 664 | return propertiesdlg_execute(param) == LC_OK; |
|---|
| 665 | } break; |
|---|
| 666 | |
|---|
| 667 | case LC_DLG_LIBRARY: { |
|---|
| 668 | return librarydlg_execute(param) == LC_OK; |
|---|
| 669 | } break; |
|---|
| 670 | |
|---|
| 671 | case LC_DLG_SELECTBYNAME: { |
|---|
| 672 | } break; |
|---|
| 673 | |
|---|
| 674 | case LC_DLG_STEPCHOOSE: { |
|---|
| 675 | } break; |
|---|
| 676 | |
|---|
| 677 | case LC_DLG_EDITGROUPS: { |
|---|
| 678 | return groupeditdlg_execute(param) == LC_OK; |
|---|
| 679 | } break; |
|---|
| 680 | |
|---|
| 681 | case LC_DLG_GROUP: { |
|---|
| 682 | return groupdlg_execute(param) == LC_OK; |
|---|
| 683 | } break; |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | return false; |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | void SystemDoPopupMenu(int nMenu, int x, int y) |
|---|
| 690 | { |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | void SystemDoWaitCursor(int code) |
|---|
| 694 | { |
|---|
| 695 | if (code == 1) |
|---|
| 696 | { |
|---|
| 697 | GdkCursor *cursor = gdk_cursor_new (GDK_WATCH); |
|---|
| 698 | gdk_window_set_cursor (((GtkWidget*)(*main_window))->window, cursor); |
|---|
| 699 | gdk_cursor_destroy (cursor); |
|---|
| 700 | } |
|---|
| 701 | else |
|---|
| 702 | { |
|---|
| 703 | GdkCursor *cursor = gdk_cursor_new (GDK_LEFT_PTR); |
|---|
| 704 | gdk_window_set_cursor (((GtkWidget*)(*main_window))->window, cursor); |
|---|
| 705 | gdk_cursor_destroy (cursor); |
|---|
| 706 | } |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | void SystemExportClipboard(File* clip) |
|---|
| 710 | { |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | File* SystemImportClipboard() |
|---|
| 714 | { |
|---|
| 715 | return NULL; |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | void SystemSetWindowCaption(char* caption) |
|---|
| 719 | { |
|---|
| 720 | gtk_window_set_title (GTK_WINDOW (((GtkWidget*)(*main_window))), caption); |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | void SystemPieceComboAdd(char* name) |
|---|
| 724 | { |
|---|
| 725 | piececombo_add(name); |
|---|
| 726 | } |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | void SystemCaptureMouse() |
|---|
| 730 | { |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | void SystemReleaseMouse() |
|---|
| 734 | { |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | void SystemStartProgressBar(int nLower, int nUpper, int nStep, const char* Text) |
|---|
| 738 | { |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | void SystemEndProgressBar() |
|---|
| 742 | { |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | void SystemStepProgressBar() |
|---|
| 746 | { |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | void SystemUpdateViewLayout() |
|---|
| 750 | { |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | String SystemGetViewLayout() |
|---|
| 754 | { |
|---|
| 755 | return String("V4|Main"); |
|---|
| 756 | } |
|---|