1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-12-22 12:53:19 +02:00

make active package track active variables (for the GUI)

If the package whose name is produced by the active variable values
is active and the variables change, then make the newly active
package the one whose name is produced by the changed variables.

This way, iterating through a table or a loop will automatically
switch to the right package, with the exception that, if the user
choses to explicitly select a different package (by clicking on
its name in the packages line), then that selection takes priority.

Explicit selection loses its priority when active package and active
variables coincide again. I.e., one can simply "catch" the active
package by activating the corresponding values.
This commit is contained in:
Werner Almesberger 2012-05-25 19:20:29 -03:00
parent b06ed92557
commit e0351bdf73
5 changed files with 19 additions and 7 deletions

8
gui.c
View File

@ -322,11 +322,19 @@ static void do_build_frames(void)
void change_world(void)
{
struct bbox before, after;
int reachable_is_active;
inst_deselect();
status_begin_reporting();
before = inst_get_bbox();
reachable_is_active = reachable_pkg && reachable_pkg == active_pkg;
reachable_pkg = NULL;
instantiate();
if (reachable_is_active && reachable_pkg &&
reachable_pkg != active_pkg) {
active_pkg = reachable_pkg;
instantiate();
}
after = inst_get_bbox();
label_in_box_bg(active_frame->label, COLOR_FRAME_SELECTED);
do_build_frames();

7
inst.c
View File

@ -35,6 +35,7 @@
struct inst *selected_inst = NULL;
struct bbox active_frame_bbox;
struct pkg *pkgs, *active_pkg, *curr_pkg;
struct pkg *reachable_pkg = NULL;
struct inst *frame_instantiating = NULL;
static struct pkg *prev_pkgs;
@ -1173,7 +1174,7 @@ void inst_end_frame(const struct frame *frame)
/* ----- package ----------------------------------------------------------- */
void inst_select_pkg(const char *name)
void inst_select_pkg(const char *name, int active)
{
struct pkg **pkg;
enum inst_prio prio;
@ -1192,6 +1193,8 @@ void inst_select_pkg(const char *name)
(*pkg)->n_samples = n_samples;
}
curr_pkg = *pkg;
if (active && name)
reachable_pkg = curr_pkg;
}
@ -1246,7 +1249,7 @@ void inst_start(void)
active_frame_bbox = bbox_zero;
prev_pkgs = pkgs;
pkgs = NULL;
inst_select_pkg(NULL);
inst_select_pkg(NULL, 0);
curr_pkg = pkgs;
frame_instantiating = NULL;
}

3
inst.h
View File

@ -134,6 +134,7 @@ extern struct inst *selected_inst;
extern struct pkg *pkgs; /* list of packages */
extern struct pkg *active_pkg; /* package selected in GUI */
extern struct pkg *curr_pkg; /* package currently being instantiated */
extern struct pkg *reachable_pkg; /* package reachable with active vars */
extern struct bbox active_frame_bbox;
/*
@ -195,7 +196,7 @@ void inst_begin_frame(struct obj *obj, struct frame *frame,
struct coord base, int active, int is_active_frame);
void inst_end_frame(const struct frame *frame);
void inst_select_pkg(const char *name);
void inst_select_pkg(const char *name, int active);
struct bbox inst_get_bbox(void);

2
meas.c
View File

@ -317,7 +317,7 @@ int instantiate_meas(int n_frames)
frame_instantiating = pkgs->insts[ip_frame];
for (pkg = pkgs; pkg; pkg = pkg->next)
if (pkg->name) {
inst_select_pkg(pkg->name);
inst_select_pkg(pkg->name, 0);
if (!instantiate_meas_pkg(n_frames))
return 0;
purge_meas(pkg);

6
obj.c
View File

@ -1,8 +1,8 @@
/*
* obj.c - Object definition model
*
* Written 2009-2011 by Werner Almesberger
* Copyright 2009-2011 by Werner Almesberger
* Written 2009-2012 by Werner Almesberger
* Copyright 2009-2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -336,7 +336,7 @@ static int generate_items(struct frame *frame, struct coord base, int active)
if (frame == frames) {
s = expand(pkg_name, frame);
/* s is NULL if expansion failed */
inst_select_pkg(s ? s : "_");
inst_select_pkg(s ? s : "_", active);
free(s);
}
inst_begin_active(active && frame == active_frame);