00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Visible.h"
00023 #include "Presentable.h"
00024 #include "Ingredients.h"
00025 #include "Root.h"
00026 #include "BaseClasses.h"
00027 #include "ParseNode.h"
00028 #include "ASN1Codes.h"
00029 #include "Engine.h"
00030 #include "Logging.h"
00031 #include "freemheg.h"
00032
00033
00034 MHVisible::MHVisible()
00035 {
00036 m_nOriginalBoxWidth = m_nOriginalBoxHeight = -1;
00037 m_nOriginalPosX = m_nOriginalPosY = 0;
00038 }
00039
00040
00041 MHVisible::MHVisible(const MHVisible &ref): MHPresentable(ref)
00042 {
00043 m_nOriginalBoxWidth = ref.m_nOriginalBoxWidth;
00044 m_nOriginalBoxHeight = ref.m_nOriginalBoxHeight;
00045 m_nOriginalPosX = ref.m_nOriginalPosX;
00046 m_nOriginalPosY = ref.m_nOriginalPosY;
00047 m_OriginalPaletteRef.Copy(ref.m_OriginalPaletteRef);
00048 }
00049
00050
00051 void MHVisible::Initialise(MHParseNode *p, MHEngine *engine)
00052 {
00053 MHPresentable::Initialise(p, engine);
00054
00055 MHParseNode *pOriginalBox = p->GetNamedArg(C_ORIGINAL_BOX_SIZE);
00056 if (! pOriginalBox) p->Failure("OriginalBoxSize missing");
00057 m_nOriginalBoxWidth = pOriginalBox->GetArgN(0)->GetIntValue();
00058 m_nOriginalBoxHeight = pOriginalBox->GetArgN(1)->GetIntValue();
00059
00060
00061 MHParseNode *pOriginalPos = p->GetNamedArg(C_ORIGINAL_POSITION);
00062 if (pOriginalPos) {
00063 m_nOriginalPosX = pOriginalPos->GetArgN(0)->GetIntValue();
00064 m_nOriginalPosY = pOriginalPos->GetArgN(1)->GetIntValue();
00065 }
00066
00067
00068 MHParseNode *pOriginalPaletteRef = p->GetNamedArg(C_ORIGINAL_PALETTE_REF);
00069 if (pOriginalPaletteRef) m_OriginalPaletteRef.Initialise(pOriginalPaletteRef->GetArgN(0), engine);
00070 }
00071
00072 void MHVisible::PrintMe(FILE *fd, int nTabs) const
00073 {
00074 MHPresentable::PrintMe(fd, nTabs);
00075 PrintTabs(fd, nTabs); fprintf(fd, ":OrigBoxSize %d %d\n", m_nOriginalBoxWidth, m_nOriginalBoxHeight);
00076 if (m_nOriginalPosX != 0 || m_nOriginalPosY != 0) {
00077 PrintTabs(fd, nTabs); fprintf(fd, ":OrigPosition %d %d\n", m_nOriginalPosX, m_nOriginalPosY);
00078 }
00079 if (m_OriginalPaletteRef.IsSet()) {
00080 PrintTabs(fd, nTabs); fprintf(fd, ":OrigPaletteRef"); m_OriginalPaletteRef.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
00081 }
00082 }
00083
00084 void MHVisible::Preparation(MHEngine *engine)
00085 {
00086 if (m_fAvailable) return;
00087 m_nBoxWidth = m_nOriginalBoxWidth;
00088 m_nBoxHeight = m_nOriginalBoxHeight;
00089 m_nPosX = m_nOriginalPosX;
00090 m_nPosY = m_nOriginalPosY;
00091 m_PaletteRef.Copy(m_OriginalPaletteRef);
00092
00093 engine->AddToDisplayStack(this);
00094 MHIngredient::Preparation(engine);
00095 }
00096
00097 void MHVisible::Destruction(MHEngine *engine)
00098 {
00099 engine->RemoveFromDisplayStack(this);
00100 MHIngredient::Destruction(engine);
00101 }
00102
00103 void MHVisible::Activation(MHEngine *engine)
00104 {
00105 if (m_fRunning) return;
00106 MHIngredient::Activation(engine);
00107 m_fRunning = true;
00108 engine->Redraw(GetVisibleArea());
00109 engine->EventTriggered(this, EventIsRunning);
00110 }
00111
00112 void MHVisible::Deactivation(MHEngine *engine)
00113 {
00114 if (! m_fRunning) return;
00115
00116
00117 QRegion region = GetVisibleArea();
00118 MHIngredient::Deactivation(engine);
00119 engine->Redraw(region);
00120 }
00121
00122
00123 MHRgba MHVisible::GetColour(const MHColour &colour)
00124 {
00125 int red = 0, green = 0, blue = 0, alpha = 0;
00126 int cSize = colour.m_ColStr.Size();
00127 if (cSize != 4) MHLOG(MHLogWarning, QString("Colour string has length %1 not 4.").arg(cSize));
00128
00129 if (cSize > 0) red = colour.m_ColStr.GetAt(0);
00130 if (cSize > 1) green = colour.m_ColStr.GetAt(1);
00131 if (cSize > 2) blue = colour.m_ColStr.GetAt(2);
00132 if (cSize > 3) alpha = 255 - colour.m_ColStr.GetAt(3);
00133 return MHRgba(red, green, blue, alpha);
00134 }
00135
00136
00137 QRegion MHVisible::GetVisibleArea()
00138 {
00139 if (! m_fRunning) return QRegion();
00140 else return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00141 }
00142
00143
00144 void MHVisible::SetPosition(int nXPosition, int nYPosition, MHEngine *engine)
00145 {
00146
00147
00148
00149 QRegion drawRegion = GetVisibleArea();
00150 m_nPosX = nXPosition;
00151 m_nPosY = nYPosition;
00152 drawRegion += GetVisibleArea();
00153 engine->Redraw(drawRegion);
00154 }
00155
00156 void MHVisible::GetPosition(MHRoot *pXPosN, MHRoot *pYPosN)
00157 {
00158 pXPosN->SetVariableValue(m_nPosX);
00159 pYPosN->SetVariableValue(m_nPosY);
00160 }
00161
00162 void MHVisible::SetBoxSize(int nWidth, int nHeight, MHEngine *engine)
00163 {
00164 QRegion drawRegion = GetVisibleArea();
00165 m_nBoxWidth = nWidth;
00166 m_nBoxHeight = nHeight;
00167 drawRegion += GetVisibleArea();
00168 engine->Redraw(drawRegion);
00169 }
00170
00171 void MHVisible::GetBoxSize(MHRoot *pWidthDest, MHRoot *pHeightDest)
00172 {
00173 pWidthDest->SetVariableValue(m_nBoxWidth);
00174 pHeightDest->SetVariableValue(m_nBoxHeight);
00175 }
00176
00177 void MHVisible::SetPaletteRef(const MHObjectRef newPalette, MHEngine *engine)
00178 {
00179 m_PaletteRef.Copy(newPalette);
00180 engine->Redraw(GetVisibleArea());
00181 }
00182
00183 void MHVisible::BringToFront(MHEngine *engine)
00184 {
00185 engine->BringToFront(this);
00186 }
00187
00188 void MHVisible::SendToBack(MHEngine *engine)
00189 {
00190 engine->SendToBack(this);
00191 }
00192
00193 void MHVisible::PutBefore(const MHRoot *pRef, MHEngine *engine)
00194 {
00195 engine->PutBefore(this, pRef);
00196 }
00197
00198 void MHVisible::PutBehind(const MHRoot *pRef, MHEngine *engine)
00199 {
00200 engine->PutBehind(this, pRef);
00201 }
00202
00203 MHLineArt::MHLineArt()
00204 {
00205 m_fBorderedBBox = true;
00206 m_nOriginalLineWidth = 1;
00207 m_OriginalLineStyle = LineStyleSolid;
00208
00209 }
00210
00211
00212 MHLineArt::MHLineArt(const MHLineArt &ref): MHVisible(ref)
00213 {
00214 m_fBorderedBBox = ref.m_fBorderedBBox;
00215 m_nOriginalLineWidth = ref.m_nOriginalLineWidth;
00216 m_OriginalLineStyle = ref.m_OriginalLineStyle;
00217 m_OrigLineColour = ref.m_OrigLineColour;
00218 m_OrigFillColour = ref.m_OrigFillColour;
00219 }
00220
00221 void MHLineArt::Initialise(MHParseNode *p, MHEngine *engine)
00222 {
00223 MHVisible::Initialise(p, engine);
00224
00225 MHParseNode *pBBBox = p->GetNamedArg(C_BORDERED_BOUNDING_BOX);
00226 if (pBBBox) m_fBorderedBBox = pBBBox->GetArgN(0)->GetBoolValue();
00227
00228 MHParseNode *pOlw = p->GetNamedArg(C_ORIGINAL_LINE_WIDTH);
00229 if (pOlw) m_nOriginalLineWidth = pOlw->GetArgN(0)->GetIntValue();
00230
00231 MHParseNode *pOls = p->GetNamedArg(C_ORIGINAL_LINE_STYLE);
00232 if (pOls) m_OriginalLineStyle = pOls->GetArgN(0)->GetIntValue();
00233
00234 MHParseNode *pOrlc = p->GetNamedArg(C_ORIGINAL_REF_LINE_COLOUR);
00235 if (pOrlc) m_OrigLineColour.Initialise(pOrlc->GetArgN(0), engine);
00236
00237 MHParseNode *pOrfc = p->GetNamedArg(C_ORIGINAL_REF_FILL_COLOUR);
00238 if (pOrfc) m_OrigFillColour.Initialise(pOrfc->GetArgN(0), engine);
00239 }
00240
00241 void MHLineArt::PrintMe(FILE *fd, int nTabs) const
00242 {
00243 MHVisible::PrintMe(fd, nTabs);
00244 if (! m_fBorderedBBox) { PrintTabs(fd, nTabs); fprintf(fd, ":BBBox false\n"); }
00245 if (m_nOriginalLineWidth != 1) { PrintTabs(fd, nTabs); fprintf(fd, ":OrigLineWidth %d\n", m_nOriginalLineWidth); }
00246 if (m_OriginalLineStyle != LineStyleSolid) {
00247 PrintTabs(fd, nTabs); fprintf(fd, ":OrigLineStyle %d\n", m_OriginalLineStyle);
00248 }
00249 if (m_OrigLineColour.IsSet()) {
00250 PrintTabs(fd, nTabs); fprintf(fd, ":OrigRefLineColour "); m_OrigLineColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
00251 }
00252 if (m_OrigFillColour.IsSet()) {
00253 PrintTabs(fd, nTabs); fprintf(fd, ":OrigRefFillColour "); m_OrigFillColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
00254 }
00255 }
00256
00257 void MHLineArt::Preparation(MHEngine *engine)
00258 {
00259 if (m_fAvailable) return;
00260
00261 m_nLineWidth = m_nOriginalLineWidth;
00262 m_LineStyle = m_OriginalLineStyle;
00263 if (m_OrigLineColour.IsSet()) m_LineColour.Copy(m_OrigLineColour);
00264 else m_LineColour.SetFromString("\000\000\000\000", 4);
00265 if (m_OrigFillColour.IsSet()) m_FillColour.Copy(m_OrigFillColour);
00266 else m_FillColour.SetFromString("\000\000\000\377", 4);
00267
00268 MHVisible::Preparation(engine);
00269 }
00270
00271
00272
00273 void MHLineArt::SetFillColour(const MHColour &colour, MHEngine *engine)
00274 {
00275 m_FillColour.Copy(colour);
00276 engine->Redraw(GetVisibleArea());
00277 }
00278
00279 void MHLineArt::SetLineColour(const MHColour &colour, MHEngine *engine)
00280 {
00281 m_LineColour.Copy(colour);
00282 engine->Redraw(GetVisibleArea());
00283 }
00284
00285 void MHLineArt::SetLineWidth(int nWidth, MHEngine *engine)
00286 {
00287 m_nLineWidth = nWidth;
00288 engine->Redraw(GetVisibleArea());
00289 }
00290
00291 void MHLineArt::SetLineStyle(int nStyle, MHEngine *engine)
00292 {
00293 m_LineStyle = nStyle;
00294 engine->Redraw(GetVisibleArea());
00295 }
00296
00297
00298 void MHRectangle::PrintMe(FILE *fd, int nTabs) const
00299 {
00300 PrintTabs(fd, nTabs); fprintf(fd, "{:Rectangle ");
00301 MHLineArt::PrintMe(fd, nTabs+1);
00302 PrintTabs(fd, nTabs);fprintf(fd, "}\n");
00303 }
00304
00305
00306 QRegion MHRectangle::GetOpaqueArea()
00307 {
00308 if (! m_fRunning) return QRegion();
00309 MHRgba lineColour = GetColour(m_LineColour);
00310 MHRgba fillColour = GetColour(m_FillColour);
00311
00312
00313 if (fillColour.alpha() != 255) return QRegion();
00314 if (lineColour.alpha() == 255 || m_nLineWidth == 0) return QRegion(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00315 if (m_nBoxWidth <= 2*m_nLineWidth || m_nBoxHeight <= 2*m_nLineWidth) return QRegion();
00316 else return QRegion(QRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
00317 m_nBoxWidth - m_nLineWidth*2, m_nBoxHeight - m_nLineWidth*2));
00318 }
00319
00320 void MHRectangle::Display(MHEngine *engine)
00321 {
00322 if (! m_fRunning) return;
00323 if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return;
00324
00325
00326 MHRgba lineColour = GetColour(m_LineColour);
00327 MHRgba fillColour = GetColour(m_FillColour);
00328 MHContext *d = engine->GetContext();
00329
00330 if (m_nBoxHeight < m_nLineWidth*2 || m_nBoxWidth < m_nLineWidth*2) {
00331
00332 d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight, lineColour);
00333 }
00334 else {
00335 d->DrawRect(m_nPosX + m_nLineWidth, m_nPosY + m_nLineWidth,
00336 m_nBoxWidth - m_nLineWidth*2, m_nBoxHeight - m_nLineWidth*2, fillColour);
00337
00338
00339 d->DrawRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nLineWidth, lineColour);
00340 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - m_nLineWidth, m_nBoxWidth, m_nLineWidth, lineColour);
00341 d->DrawRect(m_nPosX, m_nPosY + m_nLineWidth, m_nLineWidth, m_nBoxHeight - m_nLineWidth*2, lineColour);
00342 d->DrawRect(m_nPosX + m_nBoxWidth - m_nLineWidth, m_nPosY + m_nLineWidth,
00343 m_nLineWidth, m_nBoxHeight - m_nLineWidth*2, lineColour);
00344 }
00345 }
00346
00347
00348 MHInteractible::MHInteractible(MHVisible *parent): m_parent(parent)
00349 {
00350 m_fEngineResp = true;
00351 m_fHighlightStatus = false;
00352 m_fInteractionStatus = false;
00353 }
00354
00355 MHInteractible::~MHInteractible()
00356 {
00357
00358 }
00359
00360 void MHInteractible::Initialise(MHParseNode *p, MHEngine *engine)
00361 {
00362
00363 MHParseNode *pEngineResp = p->GetNamedArg(C_ENGINE_RESP);
00364 if (pEngineResp) m_fEngineResp = pEngineResp->GetArgN(0)->GetBoolValue();
00365
00366 MHParseNode *phlCol = p->GetNamedArg(C_HIGHLIGHT_REF_COLOUR);
00367 if (phlCol) m_highlightRefColour.Initialise(phlCol->GetArgN(0), engine);
00368 else engine->GetDefaultHighlightRefColour(m_highlightRefColour);
00369 m_fHighlightStatus = false;
00370 m_fInteractionStatus = false;
00371 }
00372
00373 void MHInteractible::PrintMe(FILE *fd, int nTabs) const
00374 {
00375 if (! m_fEngineResp) { PrintTabs(fd, nTabs); fprintf(fd, ":EngineResp false\n"); }
00376
00377 if (m_highlightRefColour.IsSet()) {
00378 PrintTabs(fd, nTabs);
00379 fprintf(fd, ":HighlightRefColour ");
00380 m_highlightRefColour.PrintMe(fd, nTabs+1);
00381 fprintf(fd, "\n");
00382 }
00383 }
00384
00385 void MHInteractible::Interaction(MHEngine *engine)
00386 {
00387 m_fInteractionStatus = true;
00388 engine->SetInteraction(this);
00389
00390
00391
00392 }
00393
00394 void MHInteractible::InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
00395 {
00396 if (newStatus) {
00397 if (engine->GetInteraction() == 0)
00398 Interaction(engine);
00399 }
00400 else {
00401 if (m_fInteractionStatus) {
00402 m_fInteractionStatus = false;
00403 engine->SetInteraction(0);
00404 InteractionCompleted(engine);
00405 engine->EventTriggered(m_parent, EventInteractionCompleted);
00406 }
00407 }
00408 }
00409
00410 void MHInteractible::InteractSetHighlightStatus(bool newStatus, MHEngine *engine)
00411 {
00412 if (newStatus == m_fHighlightStatus) return;
00413 m_fHighlightStatus = newStatus;
00414
00415 if (m_parent->GetRunningStatus() && m_fEngineResp)
00416 engine->Redraw(m_parent->GetVisibleArea());
00417
00418 engine->EventTriggered(m_parent, m_fHighlightStatus ? EventHighlightOn: EventHighlightOff);
00419 }
00420
00421 MHSlider::MHSlider(): MHInteractible(this)
00422 {
00423 m_orientation = SliderLeft;
00424 orig_max_value = -1;
00425 orig_min_value = initial_value = orig_step_size = 1;
00426 initial_portion = 0;
00427 m_style = SliderNormal;
00428 }
00429
00430 MHSlider::~MHSlider()
00431 {
00432 }
00433
00434 void MHSlider::Initialise(MHParseNode *p, MHEngine *engine)
00435 {
00436 MHVisible::Initialise(p, engine);
00437 MHInteractible::Initialise(p, engine);
00438
00439 MHParseNode *pOrientation = p->GetNamedArg(C_ORIENTATION);
00440 if (pOrientation)
00441 m_orientation = (enum SliderOrientation)pOrientation->GetArgN(0)->GetEnumValue();
00442
00443
00444 MHParseNode *pMin = p->GetNamedArg(C_MIN_VALUE);
00445 if (pMin) orig_min_value = pMin->GetArgN(0)->GetIntValue();
00446 else orig_min_value = 1;
00447
00448 MHParseNode *pMax = p->GetNamedArg(C_MAX_VALUE);
00449 if (pMax) orig_max_value = pMax->GetArgN(0)->GetIntValue();
00450 else orig_max_value = orig_min_value-1;
00451
00452 MHParseNode *pInit = p->GetNamedArg(C_INITIAL_VALUE);
00453 if (pInit) initial_value = pInit->GetArgN(0)->GetIntValue();
00454 else initial_value = orig_min_value;
00455
00456 MHParseNode *pPortion = p->GetNamedArg(C_INITIAL_PORTION);
00457 if (pPortion) initial_portion = pPortion->GetArgN(0)->GetIntValue();
00458 else initial_portion = orig_min_value-1;
00459
00460 MHParseNode *pStep = p->GetNamedArg(C_STEP_SIZE);
00461 if (pStep) orig_step_size = pStep->GetArgN(0)->GetIntValue();
00462 else orig_step_size = 1;
00463
00464 MHParseNode *pStyle = p->GetNamedArg(C_SLIDER_STYLE);
00465 if (pStyle) m_style = (enum SliderStyle)pStyle->GetArgN(0)->GetEnumValue();
00466 else m_style = SliderNormal;
00467
00468 MHParseNode *pslCol = p->GetNamedArg(C_SLIDER_REF_COLOUR);
00469 if (pslCol) m_sliderRefColour.Initialise(pslCol->GetArgN(0), engine);
00470 else engine->GetDefaultSliderRefColour(m_sliderRefColour);
00471 }
00472
00473 static const char *rchOrientation[] =
00474 {
00475 "left",
00476 "right",
00477 "up",
00478 "down"
00479 };
00480
00481
00482 int MHSlider::GetOrientation(const char *str)
00483 {
00484 for (int i = 0; i < (int)(sizeof(rchOrientation)/sizeof(rchOrientation[0])); i++) {
00485 if (strcasecmp(str, rchOrientation[i]) == 0) return (i+1);
00486 }
00487 return 0;
00488 }
00489
00490 static const char *rchStyle[] =
00491 {
00492 "normal",
00493 "thermometer",
00494 "proportional"
00495 };
00496
00497 int MHSlider::GetStyle(const char *str)
00498 {
00499 for (int i = 0; i < (int)(sizeof(rchStyle)/sizeof(rchStyle[0])); i++) {
00500 if (strcasecmp(str, rchStyle[i]) == 0) return (i+1);
00501 }
00502 return 0;
00503 }
00504
00505 void MHSlider::PrintMe(FILE *fd, int nTabs) const
00506 {
00507 PrintTabs(fd, nTabs); fprintf(fd, "{:Slider ");
00508 MHVisible::PrintMe(fd, nTabs+1);
00509 MHInteractible::PrintMe(fd, nTabs+1);
00510
00511 PrintTabs(fd, nTabs); fprintf(fd, ":Orientation %s\n", rchOrientation[m_orientation-1]);
00512
00513 if (initial_value >= orig_min_value) {
00514 PrintTabs(fd, nTabs+1); fprintf(fd, ":InitialValue %d\n", initial_value);
00515 }
00516
00517 if (orig_min_value != 1) {
00518 PrintTabs(fd, nTabs+1); fprintf(fd, ":MinValue %d\n", orig_min_value);
00519 }
00520
00521 if (orig_max_value > orig_min_value) {
00522 PrintTabs(fd, nTabs+1); fprintf(fd, ":MaxValue %d\n", orig_max_value);
00523 }
00524
00525 if (initial_portion >= orig_min_value) {
00526 PrintTabs(fd, nTabs+1); fprintf(fd, ":InitialPortion %d\n", initial_portion);
00527 }
00528
00529 if (orig_step_size != 1) {
00530 PrintTabs(fd, nTabs+1); fprintf(fd, ":StepSize %d\n", orig_step_size);
00531 }
00532
00533 if (m_style != SliderNormal)
00534 {
00535 PrintTabs(fd, nTabs+1);
00536 fprintf(fd, ":SliderStyle %s\n", rchStyle[m_style-1]);
00537 }
00538
00539 if (m_sliderRefColour.IsSet()) {
00540 PrintTabs(fd, nTabs+1);
00541 fprintf(fd, ":SliderRefColour ");
00542 m_sliderRefColour.PrintMe(fd, nTabs+2);
00543 fprintf(fd, "\n");
00544 }
00545
00546 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00547 }
00548
00549
00550
00551 void MHSlider::Preparation(MHEngine *engine)
00552 {
00553 MHVisible::Preparation(engine);
00554 max_value = orig_max_value;
00555 min_value = orig_min_value;
00556 step_size = orig_step_size;
00557 slider_value = initial_value;
00558 portion = initial_portion;
00559 }
00560
00561 void MHSlider::Display(MHEngine *engine)
00562 {
00563 MHContext *d = engine->GetContext();
00564 MHRgba colour;
00565 if (m_fHighlightStatus && m_fEngineResp)
00566 colour = GetColour(m_highlightRefColour);
00567 else colour = GetColour(m_sliderRefColour);
00568
00569 int major;
00570 if (m_orientation == SliderLeft || m_orientation == SliderRight)
00571 major = m_nBoxWidth;
00572 else major = m_nBoxHeight;
00573
00574 if (max_value <= min_value) return;
00575
00576 if (m_style == SliderNormal)
00577 {
00578
00579 major -= 9;
00580 int posn = major * (slider_value-min_value) / (max_value-min_value);
00581 switch (m_orientation)
00582 {
00583 case SliderLeft:
00584 d->DrawRect(m_nPosX + posn, m_nPosY, 9, m_nBoxHeight, colour);
00585 break;
00586 case SliderRight:
00587 d->DrawRect(m_nPosX + m_nBoxWidth - posn - 9, m_nPosY, 9, m_nBoxHeight, colour);
00588 break;
00589 case SliderUp:
00590 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - posn - 9, m_nBoxWidth, 9, colour);
00591 break;
00592 case SliderDown:
00593 d->DrawRect(m_nPosX, m_nPosY + posn, m_nBoxWidth, 9, colour);
00594 break;
00595 }
00596 }
00597 else {
00598
00599
00600
00601 int start = 0;
00602 int end = major * (slider_value-min_value) / (max_value-min_value);
00603 if (m_style == SliderProp)
00604 {
00605 start = end;
00606 end = major * (slider_value+portion -min_value) / (max_value-min_value);
00607 }
00608 switch (m_orientation)
00609 {
00610 case SliderLeft:
00611 d->DrawRect(m_nPosX + start, m_nPosY, end-start, m_nBoxHeight, colour);
00612 break;
00613 case SliderRight:
00614 d->DrawRect(m_nPosX + m_nBoxWidth - end, m_nPosY, end-start, m_nBoxHeight, colour);
00615 break;
00616 case SliderUp:
00617 d->DrawRect(m_nPosX, m_nPosY + m_nBoxHeight - end, m_nBoxWidth, end-start, colour);
00618 break;
00619 case SliderDown:
00620 d->DrawRect(m_nPosX, m_nPosY + start, m_nBoxWidth, end-start, colour);
00621 break;
00622 }
00623
00624 }
00625 }
00626
00627 void MHSlider::Interaction(MHEngine *engine)
00628 {
00629 MHInteractible::Interaction(engine);
00630
00631 }
00632
00633
00634
00635 void MHSlider::InteractionCompleted(MHEngine *engine)
00636 {
00637 MHInteractible::InteractionCompleted(engine);
00638
00639 engine->Redraw(GetVisibleArea());
00640 }
00641
00642
00643
00644
00645
00646 void MHSlider::KeyEvent(MHEngine *engine, int nCode)
00647 {
00648 switch (nCode)
00649 {
00650 case 15:
00651 case 16:
00652 m_fInteractionStatus = false;
00653 engine->SetInteraction(0);
00654 InteractionCompleted(engine);
00655 engine->EventTriggered(this, EventInteractionCompleted);
00656 break;
00657
00658 case 1:
00659 if (m_orientation == SliderUp)
00660 Increment(engine);
00661 else if (m_orientation == SliderDown)
00662 Decrement(engine);
00663 break;
00664
00665 case 2:
00666 if (m_orientation == SliderUp)
00667 Decrement(engine);
00668 else if (m_orientation == SliderDown)
00669 Increment(engine);
00670 break;
00671
00672 case 3:
00673 if (m_orientation == SliderLeft)
00674 Increment(engine);
00675 else if (m_orientation == SliderRight)
00676 Decrement(engine);
00677 break;
00678
00679 case 4:
00680 if (m_orientation == SliderLeft)
00681 Decrement(engine);
00682 else if (m_orientation == SliderRight)
00683 Increment(engine);
00684 break;
00685
00686 }
00687 }
00688
00689 void MHSlider::Increment(MHEngine *engine)
00690 {
00691 if (slider_value+step_size <= max_value)
00692 {
00693 slider_value += step_size;
00694 engine->Redraw(GetVisibleArea());
00695 engine->EventTriggered(this, EventSliderValueChanged);
00696 }
00697 }
00698
00699 void MHSlider::Decrement(MHEngine *engine)
00700 {
00701 if (slider_value-step_size >= min_value)
00702 {
00703 slider_value -= step_size;
00704 engine->Redraw(GetVisibleArea());
00705 engine->EventTriggered(this, EventSliderValueChanged);
00706 }
00707 }
00708
00709 void MHSlider::Step(int nbSteps, MHEngine *engine)
00710 {
00711 step_size = nbSteps;
00712 if (m_fRunning) engine->Redraw(GetVisibleArea());
00713 engine->EventTriggered(this, EventSliderValueChanged);
00714 }
00715
00716 void MHSlider::SetSliderValue(int newValue, MHEngine *engine)
00717 {
00718 slider_value = newValue;
00719 if (m_fRunning) engine->Redraw(GetVisibleArea());
00720 engine->EventTriggered(this, EventSliderValueChanged);
00721 }
00722
00723 void MHSlider::SetPortion(int newPortion, MHEngine *engine)
00724 {
00725 portion = newPortion;
00726 if (m_fRunning) engine->Redraw(GetVisibleArea());
00727 engine->EventTriggered(this, EventSliderValueChanged);
00728 }
00729
00730
00731 void MHSlider::SetSliderParameters(int newMin, int newMax, int newStep, MHEngine *engine)
00732 {
00733 min_value = newMin;
00734 max_value = newMax;
00735 step_size = newStep;
00736 slider_value = newMin;
00737 if (m_fRunning) engine->Redraw(GetVisibleArea());
00738 engine->EventTriggered(this, EventSliderValueChanged);
00739 }
00740
00741
00742 MHEntryField::MHEntryField(): MHInteractible(this)
00743 {
00744
00745 }
00746
00747 MHEntryField::~MHEntryField()
00748 {
00749
00750 }
00751
00752 void MHEntryField::Initialise(MHParseNode *p, MHEngine *engine)
00753 {
00754 MHVisible::Initialise(p, engine);
00755 MHInteractible::Initialise(p, engine);
00756
00757 }
00758
00759 void MHEntryField::PrintMe(FILE *fd, int nTabs) const
00760 {
00761 PrintTabs(fd, nTabs); fprintf(fd, "{:EntryField ");
00762 MHVisible::PrintMe(fd, nTabs+1);
00763 MHInteractible::PrintMe(fd, nTabs);
00764 fprintf(fd, "****TODO\n");
00765 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00766 }
00767
00768 MHButton::MHButton()
00769 {
00770
00771 }
00772
00773 MHButton::~MHButton()
00774 {
00775
00776 }
00777
00778 void MHButton::Initialise(MHParseNode *p, MHEngine *engine)
00779 {
00780 MHVisible::Initialise(p, engine);
00781
00782 }
00783
00784 void MHButton::PrintMe(FILE *fd, int nTabs) const
00785 {
00786 MHVisible::PrintMe(fd, nTabs);
00787
00788 }
00789
00790 MHHotSpot::MHHotSpot()
00791 {
00792
00793 }
00794
00795 MHHotSpot::~MHHotSpot()
00796 {
00797
00798 }
00799
00800 void MHHotSpot::Initialise(MHParseNode *p, MHEngine *engine)
00801 {
00802 MHButton::Initialise(p, engine);
00803
00804 }
00805
00806 void MHHotSpot::PrintMe(FILE *fd, int nTabs) const
00807 {
00808 PrintTabs(fd, nTabs); fprintf(fd, "{:Hotspot ");
00809 MHButton::PrintMe(fd, nTabs+1);
00810 fprintf(fd, "****TODO\n");
00811 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00812 }
00813
00814 MHPushButton::MHPushButton()
00815 {
00816
00817 }
00818
00819 MHPushButton::~MHPushButton()
00820 {
00821
00822 }
00823
00824 void MHPushButton::Initialise(MHParseNode *p, MHEngine *engine)
00825 {
00826 MHButton::Initialise(p, engine);
00827
00828 }
00829
00830 void MHPushButton::PrintMe(FILE *fd, int nTabs) const
00831 {
00832 PrintTabs(fd, nTabs); fprintf(fd, "{:PushButton ");
00833 MHButton::PrintMe(fd, nTabs+1);
00834 fprintf(fd, "****TODO\n");
00835 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00836 }
00837
00838 MHSwitchButton::MHSwitchButton()
00839 {
00840
00841 }
00842
00843 MHSwitchButton::~MHSwitchButton()
00844 {
00845
00846 }
00847
00848 void MHSwitchButton::Initialise(MHParseNode *p, MHEngine *engine)
00849 {
00850 MHPushButton::Initialise(p, engine);
00851
00852 }
00853
00854 void MHSwitchButton::PrintMe(FILE *fd, int nTabs) const
00855 {
00856 PrintTabs(fd, nTabs); fprintf(fd, "{:SwitchButton ");
00857 MHPushButton::PrintMe(fd, nTabs+1);
00858 fprintf(fd, "****TODO\n");
00859 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00860 }
00861
00862
00863 void MHSetColour::Initialise(MHParseNode *p, MHEngine *engine)
00864 {
00865 MHElemAction::Initialise(p, engine);
00866 if (p->GetArgCount() > 1) {
00867 MHParseNode *pIndexed = p->GetNamedArg(C_NEW_COLOUR_INDEX);
00868 MHParseNode *pAbsolute = p->GetNamedArg(C_NEW_ABSOLUTE_COLOUR);
00869 if (pIndexed) { m_ColourType = CT_Indexed; m_Indexed.Initialise(pIndexed->GetArgN(0), engine); }
00870 else if (pAbsolute) { m_ColourType = CT_Absolute; m_Absolute.Initialise(pAbsolute->GetArgN(0), engine); }
00871 }
00872 }
00873
00874 void MHSetColour::PrintArgs(FILE *fd, int) const
00875 {
00876 if (m_ColourType == CT_Indexed) { fprintf(fd, ":NewColourIndex "); m_Indexed.PrintMe(fd, 0); }
00877 else if (m_ColourType == CT_Absolute) { fprintf(fd, ":NewAbsoluteColour "); m_Absolute.PrintMe(fd, 0); }
00878 }
00879
00880 void MHSetColour::Perform(MHEngine *engine)
00881 {
00882 MHObjectRef target;
00883 m_Target.GetValue(target, engine);
00884 MHColour newColour;
00885 switch (m_ColourType)
00886 {
00887 case CT_None:
00888 {
00889
00890 newColour.SetFromString("\000\000\000\377", 4);
00891 break;
00892 }
00893 case CT_Absolute:
00894 {
00895 MHOctetString colour;
00896 m_Absolute.GetValue(colour, engine);
00897 newColour.m_ColStr.Copy(colour);
00898 break;
00899 }
00900 case CT_Indexed:
00901 newColour.m_nColIndex = m_Indexed.GetValue(engine);
00902 }
00903 SetColour(newColour, engine);
00904 }