00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "compat.h"
00022
00023 #include "Visible.h"
00024 #include "Presentable.h"
00025 #include "Ingredients.h"
00026 #include "Root.h"
00027 #include "BaseClasses.h"
00028 #include "ParseNode.h"
00029 #include "ASN1Codes.h"
00030 #include "Engine.h"
00031 #include "Logging.h"
00032 #include "freemheg.h"
00033
00034
00035 MHVisible::MHVisible()
00036 {
00037 m_nOriginalBoxWidth = m_nOriginalBoxHeight = -1;
00038 m_nOriginalPosX = m_nOriginalPosY = 0;
00039 m_nBoxWidth = m_nBoxHeight = 0;
00040 m_nPosX = m_nPosY = 0;
00041 }
00042
00043
00044 MHVisible::MHVisible(const MHVisible &ref): MHPresentable(ref)
00045 {
00046 m_nOriginalBoxWidth = ref.m_nOriginalBoxWidth;
00047 m_nOriginalBoxHeight = ref.m_nOriginalBoxHeight;
00048 m_nOriginalPosX = ref.m_nOriginalPosX;
00049 m_nOriginalPosY = ref.m_nOriginalPosY;
00050 m_nBoxWidth = ref.m_nBoxWidth;
00051 m_nBoxHeight = ref.m_nBoxHeight;
00052 m_nPosX = ref.m_nPosX;
00053 m_nPosY = ref.m_nPosY;
00054 m_OriginalPaletteRef.Copy(ref.m_OriginalPaletteRef);
00055 }
00056
00057
00058 void MHVisible::Initialise(MHParseNode *p, MHEngine *engine)
00059 {
00060 MHPresentable::Initialise(p, engine);
00061
00062 MHParseNode *pOriginalBox = p->GetNamedArg(C_ORIGINAL_BOX_SIZE);
00063
00064 if (! pOriginalBox)
00065 {
00066 p->Failure("OriginalBoxSize missing");
00067 }
00068 else
00069 {
00070 m_nOriginalBoxWidth = pOriginalBox->GetArgN(0)->GetIntValue();
00071 m_nOriginalBoxHeight = pOriginalBox->GetArgN(1)->GetIntValue();
00072 }
00073
00074
00075 MHParseNode *pOriginalPos = p->GetNamedArg(C_ORIGINAL_POSITION);
00076
00077 if (pOriginalPos)
00078 {
00079 m_nOriginalPosX = pOriginalPos->GetArgN(0)->GetIntValue();
00080 m_nOriginalPosY = pOriginalPos->GetArgN(1)->GetIntValue();
00081 }
00082
00083
00084 MHParseNode *pOriginalPaletteRef = p->GetNamedArg(C_ORIGINAL_PALETTE_REF);
00085
00086 if (pOriginalPaletteRef)
00087 {
00088 m_OriginalPaletteRef.Initialise(pOriginalPaletteRef->GetArgN(0), engine);
00089 }
00090 }
00091
00092 void MHVisible::PrintMe(FILE *fd, int nTabs) const
00093 {
00094 MHPresentable::PrintMe(fd, nTabs);
00095 PrintTabs(fd, nTabs);
00096 fprintf(fd, ":OrigBoxSize %d %d\n", m_nOriginalBoxWidth, m_nOriginalBoxHeight);
00097
00098 if (m_nOriginalPosX != 0 || m_nOriginalPosY != 0)
00099 {
00100 PrintTabs(fd, nTabs);
00101 fprintf(fd, ":OrigPosition %d %d\n", m_nOriginalPosX, m_nOriginalPosY);
00102 }
00103
00104 if (m_OriginalPaletteRef.IsSet())
00105 {
00106 PrintTabs(fd, nTabs);
00107 fprintf(fd, ":OrigPaletteRef");
00108 m_OriginalPaletteRef.PrintMe(fd, nTabs + 1);
00109 fprintf(fd, "\n");
00110 }
00111 }
00112
00113 void MHVisible::Preparation(MHEngine *engine)
00114 {
00115 if (m_fAvailable)
00116 {
00117 return;
00118 }
00119
00120 m_nBoxWidth = m_nOriginalBoxWidth;
00121 m_nBoxHeight = m_nOriginalBoxHeight;
00122 m_nPosX = m_nOriginalPosX;
00123 m_nPosY = m_nOriginalPosY;
00124 m_PaletteRef.Copy(m_OriginalPaletteRef);
00125
00126 engine->AddToDisplayStack(this);
00127 MHIngredient::Preparation(engine);
00128 }
00129
00130 void MHVisible::Destruction(MHEngine *engine)
00131 {
00132 engine->RemoveFromDisplayStack(this);
00133 MHIngredient::Destruction(engine);
00134 }
00135
00136 void MHVisible::Activation(MHEngine *engine)
00137 {
00138 if (m_fRunning)
00139 {
00140 return;
00141 }
00142
00143 MHIngredient::Activation(engine);
00144 m_fRunning = true;
00145 engine->Redraw(GetVisibleArea());
00146 engine->EventTriggered(this, EventIsRunning);
00147 }
00148
00149 void MHVisible::Deactivation(MHEngine *engine)
00150 {
00151 if (! m_fRunning)
00152 {
00153 return;
00154 }
00155
00156
00157
00158 QRegion region = GetVisibleArea();
00159 MHIngredient::Deactivation(engine);
00160 engine->Redraw(region);
00161 }
00162
00163
00164 MHRgba MHVisible::GetColour(const MHColour &colour)
00165 {
00166 int red = 0, green = 0, blue = 0, alpha = 0;
00167 int cSize = colour.m_ColStr.Size();
00168
00169 if (cSize != 4)
00170 {
00171 MHLOG(MHLogWarning, QString("Colour string has length %1 not 4.").arg(cSize));
00172 }
00173
00174
00175 if (cSize > 0)
00176 {
00177 red = colour.m_ColStr.GetAt(0);
00178 }
00179
00180 if (cSize > 1)
00181 {
00182 green = colour.m_ColStr.GetAt(1);
00183 }
00184
00185 if (cSize > 2)
00186 {
00187 blue = colour.m_ColStr.GetAt(2);
00188 }
00189
00190 if (cSize > 3)
00191 {
00192 alpha = 255 - colour.m_ColStr.GetAt(3);
00193 }
00194
00195 return MHRgba(red, green, blue, alpha);
00196 }
00197
00198
00199 QRegion MHVisible::GetVisibleArea()
00200 {
00201 if (! m_fRunning)
00202 {
00203 return QRegion();
00204 }
00205 else
00206 {
00207 return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00208 }
00209 }
00210
00211
00212 void MHVisible::SetPosition(int nXPosition, int nYPosition, MHEngine *engine)
00213 {
00214
00215
00216
00217 QRegion drawRegion = GetVisibleArea();
00218 m_nPosX = nXPosition;
00219 m_nPosY = nYPosition;
00220 drawRegion += GetVisibleArea();
00221 engine->Redraw(drawRegion);
00222 }
00223
00224 void MHVisible::GetPosition(MHRoot *pXPosN, MHRoot *pYPosN)
00225 {
00226 pXPosN->SetVariableValue(m_nPosX);
00227 pYPosN->SetVariableValue(m_nPosY);
00228 }
00229
00230 void MHVisible::SetBoxSize(int nWidth, int nHeight, MHEngine *engine)
00231 {
00232 QRegion drawRegion = GetVisibleArea();
00233 m_nBoxWidth = nWidth;
00234 m_nBoxHeight = nHeight;
00235 drawRegion += GetVisibleArea();
00236 engine->Redraw(drawRegion);
00237 }
00238
00239 void MHVisible::GetBoxSize(MHRoot *pWidthDest, MHRoot *pHeightDest)
00240 {
00241 pWidthDest->SetVariableValue(m_nBoxWidth);
00242 pHeightDest->SetVariableValue(m_nBoxHeight);
00243 }
00244
00245 void MHVisible::SetPaletteRef(const MHObjectRef newPalette, MHEngine *engine)
00246 {
00247 m_PaletteRef.Copy(newPalette);
00248 engine->Redraw(GetVisibleArea());
00249 }
00250
00251 void MHVisible::BringToFront(MHEngine *engine)
00252 {
00253 engine->BringToFront(this);
00254 }
00255
00256 void MHVisible::SendToBack(MHEngine *engine)
00257 {
00258 engine->SendToBack(this);
00259 }
00260
00261 void MHVisible::PutBefore(const MHRoot *pRef, MHEngine *engine)
00262 {
00263 engine->PutBefore(this, pRef);
00264 }
00265
00266 void MHVisible::PutBehind(const MHRoot *pRef, MHEngine *engine)
00267 {
00268 engine->PutBehind(this, pRef);
00269 }
00270
00271 MHLineArt::MHLineArt()
00272 {
00273 m_fBorderedBBox = true;
00274 m_nOriginalLineWidth = 1;
00275 m_OriginalLineStyle = LineStyleSolid;
00276 m_nLineWidth = 0;
00277 m_LineStyle = 0;
00278
00279 }
00280
00281
00282 MHLineArt::MHLineArt(const MHLineArt &ref): MHVisible(ref)
00283 {
00284 m_fBorderedBBox = ref.m_fBorderedBBox;
00285 m_nOriginalLineWidth = ref.m_nOriginalLineWidth;
00286 m_OriginalLineStyle = ref.m_OriginalLineStyle;
00287 m_OrigLineColour = ref.m_OrigLineColour;
00288 m_OrigFillColour = ref.m_OrigFillColour;
00289 m_nLineWidth = ref.m_nLineWidth;
00290 m_LineStyle = ref.m_LineStyle;
00291 }
00292
00293 void MHLineArt::Initialise(MHParseNode *p, MHEngine *engine)
00294 {
00295 MHVisible::Initialise(p, engine);
00296
00297 MHParseNode *pBBBox = p->GetNamedArg(C_BORDERED_BOUNDING_BOX);
00298
00299 if (pBBBox)
00300 {
00301 m_fBorderedBBox = pBBBox->GetArgN(0)->GetBoolValue();
00302 }
00303
00304
00305 MHParseNode *pOlw = p->GetNamedArg(C_ORIGINAL_LINE_WIDTH);
00306
00307 if (pOlw)
00308 {
00309 m_nOriginalLineWidth = pOlw->GetArgN(0)->GetIntValue();
00310 }
00311
00312
00313 MHParseNode *pOls = p->GetNamedArg(C_ORIGINAL_LINE_STYLE);
00314
00315 if (pOls)
00316 {
00317 m_OriginalLineStyle = pOls->GetArgN(0)->GetIntValue();
00318 }
00319
00320
00321 MHParseNode *pOrlc = p->GetNamedArg(C_ORIGINAL_REF_LINE_COLOUR);
00322
00323 if (pOrlc)
00324 {
00325 m_OrigLineColour.Initialise(pOrlc->GetArgN(0), engine);
00326 }
00327
00328
00329 MHParseNode *pOrfc = p->GetNamedArg(C_ORIGINAL_REF_FILL_COLOUR);
00330
00331 if (pOrfc)
00332 {
00333 m_OrigFillColour.Initialise(pOrfc->GetArgN(0), engine);
00334 }
00335 }
00336
00337 void MHLineArt::PrintMe(FILE *fd, int nTabs) const
00338 {
00339 MHVisible::PrintMe(fd, nTabs);
00340
00341 if (! m_fBorderedBBox)
00342 {
00343 PrintTabs(fd, nTabs);
00344 fprintf(fd, ":BBBox false\n");
00345 }
00346
00347 if (m_nOriginalLineWidth != 1)
00348 {
00349 PrintTabs(fd, nTabs);
00350 fprintf(fd, ":OrigLineWidth %d\n", m_nOriginalLineWidth);
00351 }
00352
00353 if (m_OriginalLineStyle != LineStyleSolid)
00354 {
00355 PrintTabs(fd, nTabs);
00356 fprintf(fd, ":OrigLineStyle %d\n", m_OriginalLineStyle);
00357 }
00358
00359 if (m_OrigLineColour.IsSet())
00360 {
00361 PrintTabs(fd, nTabs);
00362 fprintf(fd, ":OrigRefLineColour ");
00363 m_OrigLineColour.PrintMe(fd, nTabs + 1);
00364 fprintf(fd, "\n");
00365 }
00366
00367 if (m_OrigFillColour.IsSet())
00368 {
00369 PrintTabs(fd, nTabs);
00370 fprintf(fd, ":OrigRefFillColour ");
00371 m_OrigFillColour.PrintMe(fd, nTabs + 1);
00372 fprintf(fd, "\n");
00373 }
00374 }
00375
00376 void MHLineArt::Preparation(MHEngine *engine)
00377 {
00378 if (m_fAvailable)
00379 {
00380 return;
00381 }
00382
00383
00384 m_nLineWidth = m_nOriginalLineWidth;
00385 m_LineStyle = m_OriginalLineStyle;
00386
00387 if (m_OrigLineColour.IsSet())
00388 {
00389 m_LineColour.Copy(m_OrigLineColour);
00390 }
00391 else
00392 {
00393 m_LineColour.SetFromString("\000\000\000\000", 4);
00394 }
00395
00396 if (m_OrigFillColour.IsSet())
00397 {
00398 m_FillColour.Copy(m_OrigFillColour);
00399 }
00400 else
00401 {
00402 m_FillColour.SetFromString("\000\000\000\377", 4);
00403 }
00404
00405 MHVisible::Preparation(engine);
00406 }
00407
00408
00409
00410 void MHLineArt::SetFillColour(const MHColour &colour, MHEngine *engine)
00411 {
00412 m_FillColour.Copy(colour);
00413 engine->Redraw(GetVisibleArea());
00414 }
00415
00416 void MHLineArt::SetLineColour(const MHColour &colour, MHEngine *engine)
00417 {
00418 m_LineColour.Copy(colour);
00419 engine->Redraw(GetVisibleArea());
00420 }
00421
00422 void MHLineArt::SetLineWidth(int nWidth, MHEngine *engine)
00423 {
00424 m_nLineWidth = nWidth;
00425 engine->Redraw(GetVisibleArea());
00426 }
00427
00428 void MHLineArt::SetLineStyle(int nStyle, MHEngine *engine)
00429 {
00430 m_LineStyle = nStyle;
00431 engine->Redraw(GetVisibleArea());
00432 }
00433
00434
00435 void MHRectangle::PrintMe(FILE *fd, int nTabs) const
00436 {
00437 PrintTabs(fd, nTabs);
00438 fprintf(fd, "{:Rectangle ");
00439 MHLineArt::PrintMe(fd, nTabs + 1);
00440 PrintTabs(fd, nTabs);
00441 fprintf(fd, "}\n");
00442 }
00443
00444
00445 QRegion MHRectangle::GetOpaqueArea()
00446 {
00447 if (! m_fRunning)
00448 {
00449 return QRegion();
00450 }
00451
00452 MHRgba lineColour = GetColour(m_LineColour);
00453 MHRgba fillColour = GetColour(m_FillColour);
00454
00455
00456
00457 if (fillColour.alpha() != 255)
00458 {
00459 return QRegion();
00460 }
00461
00462 if (lineColour.alpha() == 255 || m_nLineWidth == 0)
00463 {
00464 return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00465 }
00466
00467 if (m_nBoxWidth <= 2 * m_nLineWidth || m_nBoxHeight <= 2 * m_nLineWidth)
00468 {
00469 return QRegion();
00470 }
00471 else return QRegion(QRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
00472 m_nBoxWidth - m_nLineWidth * 2, m_nBoxHeight - m_nLineWidth * 2));
00473 }
00474
00475 void MHRectangle::Display(MHEngine *engine)
00476 {
00477 if (! m_fRunning)
00478 {
00479 return;
00480 }
00481
00482 if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
00483 {
00484 return;
00485 }
00486
00487
00488
00489 MHRgba lineColour = GetColour(m_LineColour);
00490 MHRgba fillColour = GetColour(m_FillColour);
00491 MHContext *d = engine->GetContext();
00492
00493
00494 if (m_nBoxHeight < m_nLineWidth * 2 || m_nBoxWidth < m_nLineWidth * 2)
00495 {
00496
00497 d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight, lineColour);
00498 }
00499 else
00500 {
00501 d->DrawRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
00502 m_nBoxWidth - m_nLineWidth * 2, m_nBoxHeight - m_nLineWidth * 2, fillColour);
00503
00504
00505 d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nLineWidth, lineColour);
00506 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - m_nLineWidth, m_nBoxWidth, m_nLineWidth, lineColour);
00507 d->DrawRect(m_nPosX, m_nPosY + m_nLineWidth, m_nLineWidth, m_nBoxHeight - m_nLineWidth * 2, lineColour);
00508 d->DrawRect(m_nPosX + m_nBoxWidth - m_nLineWidth, m_nPosY + m_nLineWidth,
00509 m_nLineWidth, m_nBoxHeight - m_nLineWidth * 2, lineColour);
00510 }
00511 }
00512
00513
00514 MHInteractible::MHInteractible(MHVisible *parent): m_parent(parent)
00515 {
00516 m_fEngineResp = true;
00517 m_fHighlightStatus = false;
00518 m_fInteractionStatus = false;
00519 }
00520
00521 MHInteractible::~MHInteractible()
00522 {
00523
00524 }
00525
00526 void MHInteractible::Initialise(MHParseNode *p, MHEngine *engine)
00527 {
00528
00529 MHParseNode *pEngineResp = p->GetNamedArg(C_ENGINE_RESP);
00530
00531 if (pEngineResp)
00532 {
00533 m_fEngineResp = pEngineResp->GetArgN(0)->GetBoolValue();
00534 }
00535
00536
00537 MHParseNode *phlCol = p->GetNamedArg(C_HIGHLIGHT_REF_COLOUR);
00538
00539 if (phlCol)
00540 {
00541 m_highlightRefColour.Initialise(phlCol->GetArgN(0), engine);
00542 }
00543 else
00544 {
00545 engine->GetDefaultHighlightRefColour(m_highlightRefColour);
00546 }
00547
00548 m_fHighlightStatus = false;
00549 m_fInteractionStatus = false;
00550 }
00551
00552 void MHInteractible::PrintMe(FILE *fd, int nTabs) const
00553 {
00554 if (! m_fEngineResp)
00555 {
00556 PrintTabs(fd, nTabs);
00557 fprintf(fd, ":EngineResp false\n");
00558 }
00559
00560 if (m_highlightRefColour.IsSet())
00561 {
00562 PrintTabs(fd, nTabs);
00563 fprintf(fd, ":HighlightRefColour ");
00564 m_highlightRefColour.PrintMe(fd, nTabs + 1);
00565 fprintf(fd, "\n");
00566 }
00567 }
00568
00569 void MHInteractible::Interaction(MHEngine *engine)
00570 {
00571 m_fInteractionStatus = true;
00572 engine->SetInteraction(this);
00573
00574
00575
00576 }
00577
00578 void MHInteractible::InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
00579 {
00580 if (newStatus)
00581 {
00582 if (engine->GetInteraction() == 0)
00583 {
00584 Interaction(engine);
00585 }
00586 }
00587 else
00588 {
00589 if (m_fInteractionStatus)
00590 {
00591 m_fInteractionStatus = false;
00592 engine->SetInteraction(0);
00593 InteractionCompleted(engine);
00594 engine->EventTriggered(m_parent, EventInteractionCompleted);
00595 }
00596 }
00597 }
00598
00599 void MHInteractible::InteractSetHighlightStatus(bool newStatus, MHEngine *engine)
00600 {
00601 if (newStatus == m_fHighlightStatus)
00602 {
00603 return;
00604 }
00605
00606 m_fHighlightStatus = newStatus;
00607
00608
00609 if (m_parent->GetRunningStatus() && m_fEngineResp)
00610 {
00611 engine->Redraw(m_parent->GetVisibleArea());
00612 }
00613
00614
00615 engine->EventTriggered(m_parent, m_fHighlightStatus ? EventHighlightOn : EventHighlightOff);
00616 }
00617
00618 MHSlider::MHSlider(): MHInteractible(this)
00619 {
00620 m_orientation = SliderLeft;
00621 orig_max_value = -1;
00622 orig_min_value = initial_value = orig_step_size = 1;
00623 initial_portion = 0;
00624 m_style = SliderNormal;
00625 }
00626
00627 MHSlider::~MHSlider()
00628 {
00629 }
00630
00631 void MHSlider::Initialise(MHParseNode *p, MHEngine *engine)
00632 {
00633 MHVisible::Initialise(p, engine);
00634 MHInteractible::Initialise(p, engine);
00635
00636 MHParseNode *pOrientation = p->GetNamedArg(C_ORIENTATION);
00637
00638 if (pOrientation)
00639 {
00640 m_orientation = (enum SliderOrientation)pOrientation->GetArgN(0)->GetEnumValue();
00641 }
00642
00643
00644
00645 MHParseNode *pMin = p->GetNamedArg(C_MIN_VALUE);
00646
00647 if (pMin)
00648 {
00649 orig_min_value = pMin->GetArgN(0)->GetIntValue();
00650 }
00651 else
00652 {
00653 orig_min_value = 1;
00654 }
00655
00656 MHParseNode *pMax = p->GetNamedArg(C_MAX_VALUE);
00657
00658 if (pMax)
00659 {
00660 orig_max_value = pMax->GetArgN(0)->GetIntValue();
00661 }
00662 else
00663 {
00664 orig_max_value = orig_min_value - 1;
00665 }
00666
00667 MHParseNode *pInit = p->GetNamedArg(C_INITIAL_VALUE);
00668
00669 if (pInit)
00670 {
00671 initial_value = pInit->GetArgN(0)->GetIntValue();
00672 }
00673 else
00674 {
00675 initial_value = orig_min_value;
00676 }
00677
00678 MHParseNode *pPortion = p->GetNamedArg(C_INITIAL_PORTION);
00679
00680 if (pPortion)
00681 {
00682 initial_portion = pPortion->GetArgN(0)->GetIntValue();
00683 }
00684 else
00685 {
00686 initial_portion = orig_min_value - 1;
00687 }
00688
00689 MHParseNode *pStep = p->GetNamedArg(C_STEP_SIZE);
00690
00691 if (pStep)
00692 {
00693 orig_step_size = pStep->GetArgN(0)->GetIntValue();
00694 }
00695 else
00696 {
00697 orig_step_size = 1;
00698 }
00699
00700 MHParseNode *pStyle = p->GetNamedArg(C_SLIDER_STYLE);
00701
00702 if (pStyle)
00703 {
00704 m_style = (enum SliderStyle)pStyle->GetArgN(0)->GetEnumValue();
00705 }
00706 else
00707 {
00708 m_style = SliderNormal;
00709 }
00710
00711 MHParseNode *pslCol = p->GetNamedArg(C_SLIDER_REF_COLOUR);
00712
00713 if (pslCol)
00714 {
00715 m_sliderRefColour.Initialise(pslCol->GetArgN(0), engine);
00716 }
00717 else
00718 {
00719 engine->GetDefaultSliderRefColour(m_sliderRefColour);
00720 }
00721 }
00722
00723 static const char *rchOrientation[] =
00724 {
00725 "left",
00726 "right",
00727 "up",
00728 "down"
00729 };
00730
00731
00732 int MHSlider::GetOrientation(const char *str)
00733 {
00734 for (int i = 0; i < (int)(sizeof(rchOrientation) / sizeof(rchOrientation[0])); i++)
00735 {
00736 if (strcasecmp(str, rchOrientation[i]) == 0)
00737 {
00738 return (i + 1);
00739 }
00740 }
00741
00742 return 0;
00743 }
00744
00745 static const char *rchStyle[] =
00746 {
00747 "normal",
00748 "thermometer",
00749 "proportional"
00750 };
00751
00752 int MHSlider::GetStyle(const char *str)
00753 {
00754 for (int i = 0; i < (int)(sizeof(rchStyle) / sizeof(rchStyle[0])); i++)
00755 {
00756 if (strcasecmp(str, rchStyle[i]) == 0)
00757 {
00758 return (i + 1);
00759 }
00760 }
00761
00762 return 0;
00763 }
00764
00765 void MHSlider::PrintMe(FILE *fd, int nTabs) const
00766 {
00767 PrintTabs(fd, nTabs);
00768 fprintf(fd, "{:Slider ");
00769 MHVisible::PrintMe(fd, nTabs + 1);
00770 MHInteractible::PrintMe(fd, nTabs + 1);
00771
00772 PrintTabs(fd, nTabs);
00773 fprintf(fd, ":Orientation %s\n", rchOrientation[m_orientation-1]);
00774
00775 if (initial_value >= orig_min_value)
00776 {
00777 PrintTabs(fd, nTabs + 1);
00778 fprintf(fd, ":InitialValue %d\n", initial_value);
00779 }
00780
00781 if (orig_min_value != 1)
00782 {
00783 PrintTabs(fd, nTabs + 1);
00784 fprintf(fd, ":MinValue %d\n", orig_min_value);
00785 }
00786
00787 if (orig_max_value > orig_min_value)
00788 {
00789 PrintTabs(fd, nTabs + 1);
00790 fprintf(fd, ":MaxValue %d\n", orig_max_value);
00791 }
00792
00793 if (initial_portion >= orig_min_value)
00794 {
00795 PrintTabs(fd, nTabs + 1);
00796 fprintf(fd, ":InitialPortion %d\n", initial_portion);
00797 }
00798
00799 if (orig_step_size != 1)
00800 {
00801 PrintTabs(fd, nTabs + 1);
00802 fprintf(fd, ":StepSize %d\n", orig_step_size);
00803 }
00804
00805 if (m_style != SliderNormal)
00806 {
00807 PrintTabs(fd, nTabs + 1);
00808 fprintf(fd, ":SliderStyle %s\n", rchStyle[m_style-1]);
00809 }
00810
00811 if (m_sliderRefColour.IsSet())
00812 {
00813 PrintTabs(fd, nTabs + 1);
00814 fprintf(fd, ":SliderRefColour ");
00815 m_sliderRefColour.PrintMe(fd, nTabs + 2);
00816 fprintf(fd, "\n");
00817 }
00818
00819 PrintTabs(fd, nTabs);
00820 fprintf(fd, "}\n");
00821 }
00822
00823
00824
00825 void MHSlider::Preparation(MHEngine *engine)
00826 {
00827 MHVisible::Preparation(engine);
00828 max_value = orig_max_value;
00829 min_value = orig_min_value;
00830 step_size = orig_step_size;
00831 slider_value = initial_value;
00832 portion = initial_portion;
00833 }
00834
00835 void MHSlider::Display(MHEngine *engine)
00836 {
00837 MHContext *d = engine->GetContext();
00838 MHRgba colour;
00839
00840 if (m_fHighlightStatus && m_fEngineResp)
00841 {
00842 colour = GetColour(m_highlightRefColour);
00843 }
00844 else
00845 {
00846 colour = GetColour(m_sliderRefColour);
00847 }
00848
00849 int major;
00850
00851 if (m_orientation == SliderLeft || m_orientation == SliderRight)
00852 {
00853 major = m_nBoxWidth;
00854 }
00855 else
00856 {
00857 major = m_nBoxHeight;
00858 }
00859
00860 if (max_value <= min_value)
00861 {
00862 return;
00863 }
00864
00865 if (m_style == SliderNormal)
00866 {
00867
00868 major -= 9;
00869 int posn = major * (slider_value - min_value) / (max_value - min_value);
00870
00871 switch (m_orientation)
00872 {
00873 case SliderLeft:
00874 d->DrawRect(m_nPosX + posn, m_nPosY, 9, m_nBoxHeight, colour);
00875 break;
00876 case SliderRight:
00877 d->DrawRect(m_nPosX + m_nBoxWidth - posn - 9, m_nPosY, 9, m_nBoxHeight, colour);
00878 break;
00879 case SliderUp:
00880 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - posn - 9, m_nBoxWidth, 9, colour);
00881 break;
00882 case SliderDown:
00883 d->DrawRect(m_nPosX, m_nPosY + posn, m_nBoxWidth, 9, colour);
00884 break;
00885 }
00886 }
00887 else
00888 {
00889
00890
00891
00892 int start = 0;
00893 int end = major * (slider_value - min_value) / (max_value - min_value);
00894
00895 if (m_style == SliderProp)
00896 {
00897 start = end;
00898 end = major * (slider_value + portion - min_value) / (max_value - min_value);
00899 }
00900
00901 switch (m_orientation)
00902 {
00903 case SliderLeft:
00904 d->DrawRect(m_nPosX + start, m_nPosY, end - start, m_nBoxHeight, colour);
00905 break;
00906 case SliderRight:
00907 d->DrawRect(m_nPosX + m_nBoxWidth - end, m_nPosY, end - start, m_nBoxHeight, colour);
00908 break;
00909 case SliderUp:
00910 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - end, m_nBoxWidth, end - start, colour);
00911 break;
00912 case SliderDown:
00913 d->DrawRect(m_nPosX, m_nPosY + start, m_nBoxWidth, end - start, colour);
00914 break;
00915 }
00916
00917 }
00918 }
00919
00920 void MHSlider::Interaction(MHEngine *engine)
00921 {
00922 MHInteractible::Interaction(engine);
00923
00924 }
00925
00926
00927
00928 void MHSlider::InteractionCompleted(MHEngine *engine)
00929 {
00930 MHInteractible::InteractionCompleted(engine);
00931
00932 engine->Redraw(GetVisibleArea());
00933 }
00934
00935
00936
00937
00938
00939 void MHSlider::KeyEvent(MHEngine *engine, int nCode)
00940 {
00941 switch (nCode)
00942 {
00943 case 15:
00944 case 16:
00945 m_fInteractionStatus = false;
00946 engine->SetInteraction(0);
00947 InteractionCompleted(engine);
00948 engine->EventTriggered(this, EventInteractionCompleted);
00949 break;
00950
00951 case 1:
00952
00953 if (m_orientation == SliderUp)
00954 {
00955 Increment(engine);
00956 }
00957 else if (m_orientation == SliderDown)
00958 {
00959 Decrement(engine);
00960 }
00961
00962 break;
00963
00964 case 2:
00965
00966 if (m_orientation == SliderUp)
00967 {
00968 Decrement(engine);
00969 }
00970 else if (m_orientation == SliderDown)
00971 {
00972 Increment(engine);
00973 }
00974
00975 break;
00976
00977 case 3:
00978
00979 if (m_orientation == SliderLeft)
00980 {
00981 Increment(engine);
00982 }
00983 else if (m_orientation == SliderRight)
00984 {
00985 Decrement(engine);
00986 }
00987
00988 break;
00989
00990 case 4:
00991
00992 if (m_orientation == SliderLeft)
00993 {
00994 Decrement(engine);
00995 }
00996 else if (m_orientation == SliderRight)
00997 {
00998 Increment(engine);
00999 }
01000
01001 break;
01002
01003 }
01004 }
01005
01006 void MHSlider::Increment(MHEngine *engine)
01007 {
01008 if (slider_value + step_size <= max_value)
01009 {
01010 slider_value += step_size;
01011 engine->Redraw(GetVisibleArea());
01012 engine->EventTriggered(this, EventSliderValueChanged);
01013 }
01014 }
01015
01016 void MHSlider::Decrement(MHEngine *engine)
01017 {
01018 if (slider_value - step_size >= min_value)
01019 {
01020 slider_value -= step_size;
01021 engine->Redraw(GetVisibleArea());
01022 engine->EventTriggered(this, EventSliderValueChanged);
01023 }
01024 }
01025
01026 void MHSlider::Step(int nbSteps, MHEngine *engine)
01027 {
01028 step_size = nbSteps;
01029
01030 if (m_fRunning)
01031 {
01032 engine->Redraw(GetVisibleArea());
01033 }
01034
01035 engine->EventTriggered(this, EventSliderValueChanged);
01036 }
01037
01038 void MHSlider::SetSliderValue(int newValue, MHEngine *engine)
01039 {
01040 slider_value = newValue;
01041
01042 if (m_fRunning)
01043 {
01044 engine->Redraw(GetVisibleArea());
01045 }
01046
01047 engine->EventTriggered(this, EventSliderValueChanged);
01048 }
01049
01050 void MHSlider::SetPortion(int newPortion, MHEngine *engine)
01051 {
01052 portion = newPortion;
01053
01054 if (m_fRunning)
01055 {
01056 engine->Redraw(GetVisibleArea());
01057 }
01058
01059 engine->EventTriggered(this, EventSliderValueChanged);
01060 }
01061
01062
01063 void MHSlider::SetSliderParameters(int newMin, int newMax, int newStep, MHEngine *engine)
01064 {
01065 min_value = newMin;
01066 max_value = newMax;
01067 step_size = newStep;
01068 slider_value = newMin;
01069
01070 if (m_fRunning)
01071 {
01072 engine->Redraw(GetVisibleArea());
01073 }
01074
01075 engine->EventTriggered(this, EventSliderValueChanged);
01076 }
01077
01078
01079 MHEntryField::MHEntryField(): MHInteractible(this)
01080 {
01081
01082 }
01083
01084 MHEntryField::~MHEntryField()
01085 {
01086
01087 }
01088
01089 void MHEntryField::Initialise(MHParseNode *p, MHEngine *engine)
01090 {
01091 MHVisible::Initialise(p, engine);
01092 MHInteractible::Initialise(p, engine);
01093
01094 }
01095
01096 void MHEntryField::PrintMe(FILE *fd, int nTabs) const
01097 {
01098 PrintTabs(fd, nTabs);
01099 fprintf(fd, "{:EntryField ");
01100 MHVisible::PrintMe(fd, nTabs + 1);
01101 MHInteractible::PrintMe(fd, nTabs);
01102 fprintf(fd, "****TODO\n");
01103 PrintTabs(fd, nTabs);
01104 fprintf(fd, "}\n");
01105 }
01106
01107 MHButton::MHButton()
01108 {
01109
01110 }
01111
01112 MHButton::~MHButton()
01113 {
01114
01115 }
01116
01117 void MHButton::Initialise(MHParseNode *p, MHEngine *engine)
01118 {
01119 MHVisible::Initialise(p, engine);
01120
01121 }
01122
01123 void MHButton::PrintMe(FILE *fd, int nTabs) const
01124 {
01125 MHVisible::PrintMe(fd, nTabs);
01126
01127 }
01128
01129 MHHotSpot::MHHotSpot()
01130 {
01131
01132 }
01133
01134 MHHotSpot::~MHHotSpot()
01135 {
01136
01137 }
01138
01139 void MHHotSpot::Initialise(MHParseNode *p, MHEngine *engine)
01140 {
01141 MHButton::Initialise(p, engine);
01142
01143 }
01144
01145 void MHHotSpot::PrintMe(FILE *fd, int nTabs) const
01146 {
01147 PrintTabs(fd, nTabs);
01148 fprintf(fd, "{:Hotspot ");
01149 MHButton::PrintMe(fd, nTabs + 1);
01150 fprintf(fd, "****TODO\n");
01151 PrintTabs(fd, nTabs);
01152 fprintf(fd, "}\n");
01153 }
01154
01155 MHPushButton::MHPushButton()
01156 {
01157
01158 }
01159
01160 MHPushButton::~MHPushButton()
01161 {
01162
01163 }
01164
01165 void MHPushButton::Initialise(MHParseNode *p, MHEngine *engine)
01166 {
01167 MHButton::Initialise(p, engine);
01168
01169 }
01170
01171 void MHPushButton::PrintMe(FILE *fd, int nTabs) const
01172 {
01173 PrintTabs(fd, nTabs);
01174 fprintf(fd, "{:PushButton ");
01175 MHButton::PrintMe(fd, nTabs + 1);
01176 fprintf(fd, "****TODO\n");
01177 PrintTabs(fd, nTabs);
01178 fprintf(fd, "}\n");
01179 }
01180
01181 MHSwitchButton::MHSwitchButton()
01182 {
01183
01184 }
01185
01186 MHSwitchButton::~MHSwitchButton()
01187 {
01188
01189 }
01190
01191 void MHSwitchButton::Initialise(MHParseNode *p, MHEngine *engine)
01192 {
01193 MHPushButton::Initialise(p, engine);
01194
01195 }
01196
01197 void MHSwitchButton::PrintMe(FILE *fd, int nTabs) const
01198 {
01199 PrintTabs(fd, nTabs);
01200 fprintf(fd, "{:SwitchButton ");
01201 MHPushButton::PrintMe(fd, nTabs + 1);
01202 fprintf(fd, "****TODO\n");
01203 PrintTabs(fd, nTabs);
01204 fprintf(fd, "}\n");
01205 }
01206
01207
01208 void MHSetColour::Initialise(MHParseNode *p, MHEngine *engine)
01209 {
01210 MHElemAction::Initialise(p, engine);
01211
01212 if (p->GetArgCount() > 1)
01213 {
01214 MHParseNode *pIndexed = p->GetNamedArg(C_NEW_COLOUR_INDEX);
01215 MHParseNode *pAbsolute = p->GetNamedArg(C_NEW_ABSOLUTE_COLOUR);
01216
01217 if (pIndexed)
01218 {
01219 m_ColourType = CT_Indexed;
01220 m_Indexed.Initialise(pIndexed->GetArgN(0), engine);
01221 }
01222 else if (pAbsolute)
01223 {
01224 m_ColourType = CT_Absolute;
01225 m_Absolute.Initialise(pAbsolute->GetArgN(0), engine);
01226 }
01227 }
01228 }
01229
01230 void MHSetColour::PrintArgs(FILE *fd, int) const
01231 {
01232 if (m_ColourType == CT_Indexed)
01233 {
01234 fprintf(fd, ":NewColourIndex ");
01235 m_Indexed.PrintMe(fd, 0);
01236 }
01237 else if (m_ColourType == CT_Absolute)
01238 {
01239 fprintf(fd, ":NewAbsoluteColour ");
01240 m_Absolute.PrintMe(fd, 0);
01241 }
01242 }
01243
01244 void MHSetColour::Perform(MHEngine *engine)
01245 {
01246 MHObjectRef target;
01247 m_Target.GetValue(target, engine);
01248 MHColour newColour;
01249
01250 switch (m_ColourType)
01251 {
01252 case CT_None:
01253 {
01254
01255 newColour.SetFromString("\000\000\000\377", 4);
01256 break;
01257 }
01258 case CT_Absolute:
01259 {
01260 MHOctetString colour;
01261 m_Absolute.GetValue(colour, engine);
01262 newColour.m_ColStr.Copy(colour);
01263 break;
01264 }
01265 case CT_Indexed:
01266 newColour.m_nColIndex = m_Indexed.GetValue(engine);
01267 }
01268
01269 SetColour(newColour, engine);
01270 }