?? displaylist.cpp
字號:
if ( y == h->y && (h->x >= start && h->x < end) )
h->hit = 1;
}
typedef struct {
FlashMovie *movie;
DisplayListEntry *bhit;
} ButtonHit;
static int button_hit(void *opaque, Program *prg, DisplayListEntry *e)
{
ButtonHit *h = (ButtonHit *) opaque;
HitTable hit_table;
FlashMovie *movie = h->movie;
Rect bb,boundary;
Matrix mat;
ButtonState save;
hit_table.x = movie->mouse_x;
hit_table.y = movie->mouse_y / FRAC;
hit_table.hit = 0;
// Compute the bounding box in screen coordinates
save = e->renderState;
e->renderState = stateHitTest;
e->character->getBoundingBox(&boundary,e);
e->renderState = save;
mat = (*movie->gd->adjust) * e->renderMatrix;
transformBoundingBox(&bb, &mat, &boundary, 1);
// Check if mouse is within bb
if (movie->mouse_x < bb.xmin) return 0;
if (movie->mouse_x > bb.xmax) return 0;
if (movie->mouse_y < bb.ymin) return 0;
if (movie->mouse_y > bb.ymax) return 0;
e->character->getRegion(movie->gd, &e->renderMatrix,
&hit_table, button_hit_func);
if (hit_table.hit) {
h->bhit = e;
return 1;
} else {
return 0;
}
}
static int button_reset(void *opaque, Program *prg, DisplayListEntry *e)
{
if (e->renderState != stateUp) {
e->owner->updateBoundingBox(e);
e->oldState = e->renderState;
e->renderState = stateUp;
((Button *)e->character)->updateButtonState(e);
e->owner->updateBoundingBox(e);
}
return 0;
}
/* update the button states according to the current mouse state & return the list of actions */
void
DisplayList::updateButtons(FlashMovie *movie)
{
DisplayListEntry *bhit;
ButtonHit h;
if (movie->mouse_active) {
h.bhit = NULL;
h.movie = movie;
exploreButtons(movie, &h, button_hit);
bhit = h.bhit;
/* set every button to not hit */
exploreButtons(movie, NULL, button_reset);
if (bhit) {
ButtonState state;
if (movie->button_pressed) {
state = stateDown;
} else {
state = stateOver;
}
if (state != bhit->renderState) {
bhit->owner->updateBoundingBox(bhit);
bhit->renderState = state;
((Button *)bhit->character)->updateButtonState(bhit);
bhit->owner->updateBoundingBox(bhit);
movie->cur_focus = bhit;
if (movie->cursorOnOff)
movie->cursorOnOff(1,movie->cursorOnOffClientData);
}
} else {
if (movie->cursorOnOff)
movie->cursorOnOff(0,movie->cursorOnOffClientData);
}
}
}
typedef struct {
ActionRecord *action; // Action to do
Program *prg; // Context program
} ButtonAction;
static int button_action(void *opaque, Program *prg, DisplayListEntry *e)
{
ButtonAction *h = (ButtonAction *)opaque;
static ActionRecord actionRefresh;
static ActionRecord soundFx;
Button *b;
ActionRecord **paction;
int n;
actionRefresh.action = ActionRefresh;
actionRefresh.next = 0;
soundFx.action = ActionPlaySound;
soundFx.next = &actionRefresh;
b = (Button *)e->character;
if (e->oldState != e->renderState) {
paction = &actionRefresh.next;
if (b->conditionList) {
*paction = b->getActionFromTransition(e->renderState, e->oldState);
} else if (e->renderState == stateDown) {
/* if the button is pressed and
no condition list is defined*/
*paction = b->actionRecords;
}
switch(e->renderState) {
case stateUp:
n = 0;
break;
case stateOver:
n = 1;
break;
default:
/* case stateDown: */
n = 2;
break;
}
if (b->sound[n]) {
soundFx.sound = b->sound[n];
h->action = &soundFx;
} else {
h->action = &actionRefresh;
}
e->oldState = e->renderState;
h->prg = prg;
return 2;
}
h->action = 0; // Nothing to do about this
return 0;
}
int computeActions(FlashMovie *movie, Program **prg, ActionRecord **ar)
{
ButtonAction h;
h.action = NULL;
exploreButtons(movie, &h, button_action);
if (h.action) {
*prg = h.prg;
*ar = h.action;
return 1;
}
return 0;
}
#define FOCUS_ZOOM 1.5
/* in pixels */
#define FOCUS_SIZE_MIN 50
#define FOCUS_TRANSLATE 15
int
DisplayList::render(GraphicDevice *gd, Matrix *render_matrix, Cxform *cxform)
{
DisplayListEntry *e,*cur_focus;
int sprite = 0;
long n = 0;
Cxform cxf,*cxf1;
Rect bb,boundary;
cur_focus = NULL;
/*
if (isSprite == 0) {
if (this->bbox.xmin == LONG_MAX) return 0;
gd->updateClippingRegion(&this->bbox, render_matrix);
gd->clearCanvas();
}
*/
for (e = list; e; e = e->next)
{
#if PRINT
printf("Character %3d @ %3d\n", e->character ? e->character->getTagId() : 0, e->depth);
#endif
if (e->character) {
Matrix mat;
if (render_matrix) {
mat = *render_matrix;
}
if (e->matrix) {
mat = mat * (*e->matrix);
}
/* fast clipping */
// If object boundaries are outside current clip region give up with rendering
e->character->getBoundingBox(&boundary,e);
if (boundary.xmin != LONG_MAX) {
Matrix tmat;
tmat = (*gd->adjust) * mat;
transformBoundingBox(&bb, &tmat, &boundary, 1);
bb.xmin = bb.xmin >> FRAC_BITS;
bb.ymin = bb.ymin >> FRAC_BITS;
bb.xmax = (bb.xmax + FRAC - 1) >> FRAC_BITS;
bb.ymax = (bb.ymax + FRAC - 1) >> FRAC_BITS;
if (bb.xmin >= gd->clip_rect.xmax ||
bb.xmax <= gd->clip_rect.xmin ||
bb.ymin >= gd->clip_rect.ymax ||
bb.ymax <= gd->clip_rect.ymin) {
continue;
}
}
if (cxform == NULL) {
cxf1 = e->cxform;
}
else if (e->cxform == NULL) {
cxf1 = cxform;
}
else {
cxf1 = &cxf;
cxf.ra = cxform->ra * e->cxform->ra;
cxf.ga = cxform->ga * e->cxform->ga;
cxf.ba = cxform->ba * e->cxform->ba;
cxf.aa = cxform->aa * e->cxform->aa;
cxf.rb = (long)(cxform->ra * e->cxform->rb + cxform->rb);
cxf.gb = (long)(cxform->ga * e->cxform->gb + cxform->gb);
cxf.bb = (long)(cxform->ba * e->cxform->bb + cxform->bb);
cxf.ab = (long)(cxform->aa * e->cxform->ab + cxform->ab);
}
if (e->character->isButton()) {
Button *b = (Button *) e->character;
e->renderMatrix = mat;
if (e->renderState != stateUp && movie->mouse_active == 0) {
cur_focus = e;
((Button *)e->character)->updateButtonState(e);
}
if (b->execute(gd, &mat, cxf1, e->renderState)) {
sprite = 1;
}
} else {
if (e->character->execute(gd, &mat, cxf1)) {
sprite = 1;
}
}
n++;
}
}
#if 0
{
/* display the bounding box (debug) */
Matrix tmat;
long x1,x2,y1,y2;
Color white;
white.red = 255;
white.green = white.blue = 0;
gd->setForegroundColor(white);
if (render_matrix) {
tmat = (*gd->adjust) * (*render_matrix);
} else {
tmat = *gd->adjust;
}
x1 = bbox.xmin;
y1 = bbox.ymin;
x2 = bbox.xmax;
y2 = bbox.ymax;
gd->drawLine(tmat.getX(x1,y1),tmat.getY(x1,y1),tmat.getX(x2,y1),tmat.getY(x2,y1),10*FRAC);
gd->drawLine(tmat.getX(x2,y1),tmat.getY(x2,y1),tmat.getX(x2,y2),tmat.getY(x2,y2),10*FRAC);
gd->drawLine(tmat.getX(x2,y2),tmat.getY(x2,y2),tmat.getX(x1,y2),tmat.getY(x1,y2),10*FRAC);
gd->drawLine(tmat.getX(x1,y2),tmat.getY(x1,y2),tmat.getX(x1,y1),tmat.getY(x1,y1),10*FRAC);
bbox.print();
}
#endif
// Reset clipping zone
bbox.reset();
return sprite;
}
void
DisplayList::getBoundary(Rect *bb)
{
DisplayListEntry *e;
Rect boundary;
bb->reset();
for (e = list; e; e = e->next)
{
if (e->character) {
e->character->getBoundingBox(&boundary,e);
transformBoundingBox(bb, e->matrix, &boundary, 0);
}
}
}
extern "C" {
void dump_buttons(FlashHandle flashHandle)
{
#if 0
Rect rect;
DisplayListEntry *e;
FlashMovie *movie;
movie = (FlashMovie *)flashHandle;
for (e = movie->first_button; e; e = e->next_button) {
computeBBox(movie,&rect,e);
printf("button: id=%d pos=%d %d %d %d\n",
e->character->getTagId(),
rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
#endif
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -