Presentation is loading. Please wait.

Presentation is loading. Please wait.

GUI For the 8-Puzzle A minimal layout: All background colors and fonts are specified in a resource file.

Similar presentations


Presentation on theme: "GUI For the 8-Puzzle A minimal layout: All background colors and fonts are specified in a resource file."— Presentation transcript:

1 GUI For the 8-Puzzle A minimal layout: All background colors and fonts are specified in a resource file.

2 How It Was Laid Out ● Tiles are xmDrawnButton s: – Have drawing areas on their face – Appearance of “pushing in” is disabled by default ● Tile container is an xmBulletinBoard ● Options are xmPushButton s ● Option container is a vertical xmRowColumn ● Move count is an xmLabel ● Everything is contained in an xmForm

3 Parallel Representations Keep two "parallel" representations: 1 Internal representation that you have already created 2 Visual representation that mirrors the internal one This requires that the two representations be kept "in step". It also requires you to think about what the GUI needs from the other classes.

4 Class Relationships ProblemSolverQueue ActionListActionItemPriorityQueueFrontQueue RearQueue State MaxPriorityQueueMinPriorityQueue Interface Since the Solver knows about everything, associate the GUI with the Solver:

5 Previous Top-Level Program int main(...) {... Problem p = new PuzzleProblemInfo(...); MinPriorityQueue q = new MinPriorityQueueInfo(qsize); Solver s = new SolverInfo(p, q); s->solve(); }

6 New Top-Level Program int main(...) {... Problem p = new PuzzleProblemInfo(...); MinPriorityQueue q = new MinPriorityQueueInfo(qsize); Solver s = new SolverInfo(p, q); Interface i = new InterfaceInfo(s); } The InterfaceInfo constructor can create the widgets and callbacks, realize the widgets, and enter the main loop.

7 Determining Which Tile is Clicked ● Recall that every callback provides the widget w as its first argument ● Use XtVaGetValues to retrieve the widget's resource values: – XtVaGetValues(, {,,}* NULL) – XtVaGetValues(w, XmNx, &x, XmNy, &y, NULL) – x and y must be of type Position, which is a built-in X window system type that behaves like an Integer or int ● Now (x,y) is the pixel location of the clicked widget ● Use (x,y) to translate to the internal representation of the board and check if it is adjacent to the space

8 Moving the Tile ● Once you've determined the tile and the direction it is to move: – Compute a new target (x,y) location for the widget – Set the new location resources using XtVaSetValues ● To simulate slow tile motion, move the widget one pixel at a time within a loop – If motion still seems too fast, add a waiting loop, within the outer loop, that does nothing but count to some appropriate number

9 Handling a Solve Request ● Since the InterfaceInfo object contains a SolverInfo object, the Solve button callback can directly solve the current puzzle ● Since the solution is only a (reversed) list of items, you need to process the list 283 164 75 283 14 765 23 184 765 23 184 765 123 84 765 123 84 765 Determine which tile moved between each pair of states. Tell that widget to move itself (can reuse tile motion code).


Download ppt "GUI For the 8-Puzzle A minimal layout: All background colors and fonts are specified in a resource file."

Similar presentations


Ads by Google