Mercurial > hg > forks > yadex
diff src/editloop.cc @ 80:2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Sep 2011 17:39:49 +0300 |
parents | e2020fcc4c51 |
children | 002bc70a3982 |
line wrap: on
line diff
--- a/src/editloop.cc Mon Sep 26 17:14:54 2011 +0300 +++ b/src/editloop.cc Mon Sep 26 17:39:49 2011 +0300 @@ -73,7 +73,6 @@ static int zoom_fit(edit_t &); -extern bool InfoShown; /* should we display the info bar? */ static int menubar_out_y1; /* FIXME */ @@ -104,7 +103,7 @@ int n = 0; /* number of levels in the dir. that match */ get_levels_that_match: - for (dir = MasterDir; dir; dir = dir->next) + for (dir = cfg.MasterDir; dir; dir = dir->next) { if (levelname2levelno(dir->dir.name) > 0 && (levelno == 0 @@ -230,12 +229,12 @@ e.global = false; e.tool = TOOL_NORMAL; e.grid_step = 128; - e.grid_step_min = GridMin; - e.grid_step_max = GridMax; + e.grid_step_min = cfg.GridMin; + e.grid_step_max = cfg.GridMax; e.grid_step_locked = 0; e.grid_shown = 1; e.grid_snap = 1; - e.infobar_shown = (bool) InfoShown; + e.infobar_shown = cfg.InfoShown; e.objinfo_shown = true; e.show_object_numbers = false; e.show_things_squares = false; @@ -260,19 +259,19 @@ MadeMapChanges = 0; // Sane defaults - Scale = 1.0; - OrigX = 0; - OrigY = 0; + cfg.Scale = 1.0; + cfg.OrigX = 0; + cfg.OrigY = 0; edit_zoom_init(); - if (zoom_default == 0) + if (cfg.zoom_default == 0) { zoom_fit(e); } else { - int r = edit_set_zoom(&e, zoom_default / 100.0); + int r = edit_set_zoom(&e, cfg.zoom_default / 100.0); if (r == 0) CenterMapAroundCoords((MapMinX + MapMaxX) / 2, (MapMinY + MapMaxY) / 2); @@ -281,7 +280,7 @@ /* Create the menu bar */ { - e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); + e.menubar->compute_menubar_coords(0, 0, cfg.ScrMaxX, cfg.ScrMaxY); e.mb_menu[MBM_FILE] = new Menu(NULL, "~Save", YK_F2, 0, @@ -862,7 +861,7 @@ else if (is.key == YE_RESIZE) { SetWindowSize(is.width, is.height); - e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY); + e.menubar->compute_menubar_coords(0, 0, cfg.ScrMaxX, cfg.ScrMaxY); RedrawMap = 1; goto done2; } @@ -882,8 +881,8 @@ if (deltaX != 0 || deltaY != 0) { - OrigX += (deltaX / Scale); - OrigY -= (deltaY / Scale); + cfg.OrigX += (deltaX / cfg.Scale); + cfg.OrigY -= (deltaY / cfg.Scale); RedrawMap = 1; DragMapMoveX = is.x; DragMapMoveY = is.y; @@ -974,7 +973,7 @@ && IsSelected(e.Selected, object.num) && object == e.clicked && is.time - e.click_time <= - (unsigned long) double_click_timeout) + (unsigned long) cfg.double_click_timeout) { // Very important! If you don't do that, the release of the // click that closed the properties menu will drag the object. @@ -1210,7 +1209,7 @@ else if (is.key == YK_F1 + YK_SHIFT) { Rgbbmp b; - window_to_rgbbmp(0, 0, (int) ScrMaxX + 1, (int) ScrMaxY + 1, + window_to_rgbbmp(0, 0, (int) cfg.ScrMaxX + 1, (int) cfg.ScrMaxY + 1, b); rgbbmp_to_rawppm(b, "yadex.ppm"); //ScreenShot (); @@ -1235,7 +1234,7 @@ /* [F2] save level into pwad, prompt for the file name every time but keep the same level name. */ - else if (is.key == YK_F2 && Registered) + else if (is.key == YK_F2 && cfg.Registered) { if (!CheckStartingPos()) goto cancel_save; @@ -1255,14 +1254,14 @@ SaveLevelData(outfile, newlevelname); levelname = newlevelname; // Sigh. Shouldn't have to do that. Level must die ! - Level = FindMasterDir(MasterDir, levelname); + Level = FindMasterDir(cfg.MasterDir, levelname); cancel_save: RedrawMap = 1; } /* [F3] save level into pwad, prompt for the file name and level name. */ - else if (is.key == YK_F3 && Registered) + else if (is.key == YK_F3 && cfg.Registered) { char *outfile; const char *newlevelname; @@ -1277,7 +1276,7 @@ { /* horrible but it works... */ // Horrible indeed -- AYM 1999-07-30 - newLevel = FindMasterDir(MasterDir, newlevelname); + newLevel = FindMasterDir(cfg.MasterDir, newlevelname); if (!newLevel) nf_bug("newLevel is NULL"); // Debatable ! -- AYM 2001-05-29 if (Level) // If new level ("create" command), Level is NULL @@ -1450,58 +1449,58 @@ // [Left], [Right], [Up], [Down]: - // scroll <scroll_less> percents of a screenful. - else if (is.key == YK_LEFT && MAPX(ScrCenterX) > -20000) + // scroll <cfg.scroll_less> percents of a screenful. + else if (is.key == YK_LEFT && MAPX(cfg.ScrCenterX) > -20000) { - OrigX -= (int) ((double) ScrMaxX * scroll_less / 100 / Scale); + cfg.OrigX -= (int) ((double) cfg.ScrMaxX * cfg.scroll_less / 100 / cfg.Scale); RedrawMap = 1; } - else if (is.key == YK_RIGHT && MAPX(ScrCenterX) < 20000) + else if (is.key == YK_RIGHT && MAPX(cfg.ScrCenterX) < 20000) { - OrigX += (int) ((double) ScrMaxX * scroll_less / 100 / Scale); + cfg.OrigX += (int) ((double) cfg.ScrMaxX * cfg.scroll_less / 100 / cfg.Scale); RedrawMap = 1; } - else if (is.key == YK_UP && MAPY(ScrCenterY) < 20000) + else if (is.key == YK_UP && MAPY(cfg.ScrCenterY) < 20000) { - OrigY += (int) ((double) ScrMaxY * scroll_less / 100 / Scale); + cfg.OrigY += (int) ((double) cfg.ScrMaxY * cfg.scroll_less / 100 / cfg.Scale); RedrawMap = 1; } - else if (is.key == YK_DOWN && MAPY(ScrCenterY) > -20000) + else if (is.key == YK_DOWN && MAPY(cfg.ScrCenterY) > -20000) { - OrigY -= (int) ((double) ScrMaxY * scroll_less / 100 / Scale); + cfg.OrigY -= (int) ((double) cfg.ScrMaxY * cfg.scroll_less / 100 / cfg.Scale); RedrawMap = 1; } // [Pgup], [Pgdn], [Home], [End]: - // scroll <scroll_more> percents of a screenful. - else if (is.key == YK_PU && MAPY(ScrCenterY) < /*MapMaxY */ 20000) + // scroll <cfg.scroll_more> percents of a screenful. + else if (is.key == YK_PU && MAPY(cfg.ScrCenterY) < /*MapMaxY */ 20000) { - OrigY += (int) ((double) ScrMaxY * scroll_more / 100 / Scale); + cfg.OrigY += (int) ((double) cfg.ScrMaxY * cfg.scroll_more / 100 / cfg.Scale); RedrawMap = 1; } else if (is.key == YK_PD - && MAPY(ScrCenterY) > /*MapMinY */ -20000) + && MAPY(cfg.ScrCenterY) > /*MapMinY */ -20000) { - OrigY -= (int) ((double) ScrMaxY * scroll_more / 100 / Scale); + cfg.OrigY -= (int) ((double) cfg.ScrMaxY * cfg.scroll_more / 100 / cfg.Scale); RedrawMap = 1; } else if (is.key == YK_HOME - && MAPX(ScrCenterX) > /*MapMinX */ -20000) + && MAPX(cfg.ScrCenterX) > /*MapMinX */ -20000) { - OrigX -= (int) ((double) ScrMaxX * scroll_more / 100 / Scale); + cfg.OrigX -= (int) ((double) cfg.ScrMaxX * cfg.scroll_more / 100 / cfg.Scale); RedrawMap = 1; } else if (is.key == YK_END - && MAPX(ScrCenterX) < /*MapMaxX */ 20000) + && MAPX(cfg.ScrCenterX) < /*MapMaxX */ 20000) { - OrigX += (int) ((double) ScrMaxX * scroll_more / 100 / Scale); + cfg.OrigX += (int) ((double) cfg.ScrMaxX * cfg.scroll_more / 100 / cfg.Scale); RedrawMap = 1; } else if (is.key == ' ') { e.extra_zoom = !e.extra_zoom; - edit_set_zoom(&e, Scale * (e.extra_zoom ? 4 : 0.25)); + edit_set_zoom(&e, cfg.Scale * (e.extra_zoom ? 4 : 0.25)); RedrawMap = 1; } @@ -1639,7 +1638,7 @@ else ForgetSelection(&e.Selected); } - if (GetMaxObjectNum(e.obj_type) >= 0 && Select0 && !e.global) + if (GetMaxObjectNum(e.obj_type) >= 0 && cfg.Select0 && !e.global) { e.highlighted.type = e.obj_type; e.highlighted.num = 0; @@ -2066,7 +2065,7 @@ else if (is.key == YK_DEL && (e.Selected || e.highlighted())) /* 'Del' */ { if (e.obj_type == OBJ_THINGS - || Expert + || cfg.Expert || Confirm(-1, -1, (e.Selected && e.Selected->next ? "Do you really want to delete these objects?" @@ -2444,45 +2443,43 @@ // through the menus. if (is.in_window - && autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0) + && cfg.autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0) { unsigned distance; // In pixels #define actual_move(total,dist) \ - ((int) (((total * autoscroll_amp / 100)\ - * ((double) (autoscroll_edge - dist) / autoscroll_edge))\ - / Scale)) + ((int) (((total * cfg.autoscroll_amp / 100) * ((double) (cfg.autoscroll_edge - dist) / cfg.autoscroll_edge)) / cfg.Scale)) distance = is.y; // The reason for the second member of the condition // is that we don't want to scroll when the user is // simply reaching for a menu... - if (distance <= autoscroll_edge + if (distance <= cfg.autoscroll_edge && e.menubar->is_under_menubar_item(is.x) < 0) { - if (MAPY(ScrCenterY) < /*MapMaxY */ 20000) + if (MAPY(cfg.ScrCenterY) < /*MapMaxY */ 20000) { - OrigY += actual_move(ScrMaxY, distance); + cfg.OrigY += actual_move(cfg.ScrMaxY, distance); RedrawMap = 1; } } - distance = ScrMaxY - is.y; - if (distance <= autoscroll_edge) + distance = cfg.ScrMaxY - is.y; + if (distance <= cfg.autoscroll_edge) { - if (MAPY(ScrCenterY) > /*MapMinY */ -20000) + if (MAPY(cfg.ScrCenterY) > /*MapMinY */ -20000) { - OrigY -= actual_move(ScrMaxY, distance); + cfg.OrigY -= actual_move(cfg.ScrMaxY, distance); RedrawMap = 1; } } distance = is.x; - if (distance <= autoscroll_edge) + if (distance <= cfg.autoscroll_edge) { - if (MAPX(ScrCenterX) > /*MapMinX */ -20000) + if (MAPX(cfg.ScrCenterX) > /*MapMinX */ -20000) { - OrigX -= actual_move(ScrMaxX, distance); + cfg.OrigX -= actual_move(cfg.ScrMaxX, distance); RedrawMap = 1; } } @@ -2492,12 +2489,12 @@ // simply reaching for the "Help" menu... // Note: the ordinate "3 * FONTH" is of course not // critical. It's just a rough approximation. - distance = ScrMaxX - is.x; - if (distance <= autoscroll_edge && (unsigned) is.y >= 3 * FONTH) + distance = cfg.ScrMaxX - is.x; + if (distance <= cfg.autoscroll_edge && (unsigned) is.y >= 3 * FONTH) { - if (MAPX(ScrCenterX) < /*MapMaxX */ 20000) + if (MAPX(cfg.ScrCenterX) < /*MapMaxX */ 20000) { - OrigX += actual_move(ScrMaxX, distance); + cfg.OrigX += actual_move(cfg.ScrMaxX, distance); RedrawMap = 1; } } @@ -2548,8 +2545,8 @@ int MapSizeX = MapMaxX - MapMinX, MapSizeY = MapMaxY - MapMinY; - double xzoom = MapSizeX ? (0.95f * ScrMaxX / (double) MapSizeX) : 1, - yzoom = MapSizeY ? (0.9f * ScrMaxY / (double) MapSizeY) : 1; + double xzoom = MapSizeX ? (0.95f * cfg.ScrMaxX / (double) MapSizeX) : 1, + yzoom = MapSizeY ? (0.9f * cfg.ScrMaxY / (double) MapSizeY) : 1; int r = edit_set_zoom(&e, y_min(xzoom, yzoom)); if (r != 0)