Autor Beitrag
bugo-hoss
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 10:56 
Hallo zusammen,
ich bin grade dabei das Spiel "Carcasonne" zu programmieren.
Es geht darum dass Spielkarten aneinandergelegt werden um sich eine Art Stadt zu bauen.
Momentan habe ich einen Bitbutton , der beim klicken eine Nebenliegende Spielkarte (Image)aufdeckt.
Das Problem ist, dass diese Karte in einem Stringgrid platziert werden soll, dass bereits schon einheitlich große Zellen besitzt.
Es gibt meiner Ansicht nach jetzt 2 Möglichkeiten.
Entweder man zieht die aktuell aufgedeckte Karte mit der Maus in eine Zelle (müsste 100% in der Zelle sitzen) oder man klickt auf die Karte und anschließend auf eine Zelle in der diese platziert werden soll. (Die Karten und die Zellen besitzen die gleiche Größe!)
Habt ihr eine Idee wie ich die leichtere Variante umsetzen könnte? Habt auch schon ein wenig im Forum geschaut, aber noch nichts hilfreiches gefunden...


Zuletzt bearbeitet von bugo-hoss am Do 25.01.07 08:58, insgesamt 1-mal bearbeitet
curtiss
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 59



BeitragVerfasst: Mi 24.01.07 11:03 
ich würde ne abfrage machen,

wenn mausposition kleiner als dann
feld 1

ansonsten

feld 2

also wenn du 2 felder hast die insg. 20px lang sind und die maus iss mit dem bildchen auf pos 9 dann packt ers ins erste Feld ansonsten (also wenns 10 oder höher iss) ins 2te feld. Das ganze natürlcih nach xy anpassen und variabel zu einer funktion machen.

Ich stand auch mal vor der aufgabe, dass iss dass was ich mir dazu aufgeschrieben habe. Aber ich habe jetzt leider keinen code für dich.

Ich denke auch nicht dass du ein Bild in ein STRINGgrid einfügen kannst !


MFG
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 24.01.07 11:04 
Wo liegt jetzt das Problem? Beim Ziehen? Oder bei der Anzeige des Bilds im StringGrid?

Jedenfalls würde ich statt des StringGrids entweder eine eigene Komponente empfehlen oder zumindest ein DrawGrid. Letztres ist nämlich für sowas da ;-).
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 11:09 
hehe naja das problem is zum einen, welche möglichkeit is die leichtere ( ziehen oder per klick ) und zum anderen, wie setz ich es um ;) danke schon mal für die flinken antworten!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 24.01.07 11:11 
Das mit dem Ziehen ist nicht das Problem. Du setzt DragMode auf automatisch und schon kannst du was ziehen. Dann musst du noch in der Zielkomponente auf DragOver reagieren und den Ziehvorgang annehmen (Accept := True) und in DragDrop das Bild ablegen.
In welche Zelle das Bild kommt musst du dann berechnen. Mit "div Spaltenbreite" und "div Zeilenhöhe" bekommst du ja die richtige Zelle recht einfach heraus.
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 11:14 
also ich klick jetzt in meiner form auf das image, geh auf events wähle Ondragdrop aus und wie klappt das mit dem auf automatisch setzen?
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 11:15 
okay habs gefunden^^
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 11:22 
okay, also der drag mode is nun auf automatic, beim ausführen des progs und klicken aufs image verändert sich auch der cursor, aber es bewegt sich leider noch net
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 24.01.07 11:29 
Dass das Bild nicht am Mauszeiger klebt ist nochmal was anderes. Aber es sollte beim Ziehen eben erstmal der DragCursor kommen, und dann geht erstmal das Ziehen.
Das visuell darzustellen ist nochmal ne andere Geschichte...
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 24.01.07 11:32 
joa also zumindest wird aus dem cursor beim klicken schon mal nen stop zeichen^^ also kreis mit schrägstrich, hmm geht das anzeigen nicht auch irgentwie einzustellen? also per auswahl im objectinspector?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 24.01.07 12:33 
Das kann man doch alles später machen, das ist doch reine Kosmetik... ;-)
Erstmal muss es mal funktionieren...

user profile iconbugo-hoss hat folgendes geschrieben:
joa also zumindest wird aus dem cursor beim klicken schon mal nen stop zeichen^^
Beim Klicken? Ich dachte das wäre eben ein Versehen gewesen als du das geschrieben hast?
Du ziehst doch die Maus. Jedenfalls zeigt dir der Mauszeiger an, dass du das Bild an dieser Stelle nicht ablegen kannst.
Wenn du bei einer Komponente in OnDragOver Accept auf True setzt, dann ändert sich da der Mauszeiger um anzuzeigen, dass man hier ablegen kann.
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Do 25.01.07 08:53 
danke für den tipp: drack over accept ;) joa also der cursor wird beim klicken zum dragcursor jedoch beim ziehen übers programm halt dieses "Verboten-Zeichen".
is ja glaub auch klar weil ich ja im prinzip irgentwo mal sagen müsste wo es platziert werden darf. hab mein stringgrid jetzt mal mit nem DRAWGRID ausgetauscht.
bin leider net der hellste aber hat jemand schon mal etwas derartiges programmiert, der mir anhand eines quelltextauszugs erklären könnte wie die bilder dort hineingezogen werden könnten?
merci
bugo-hoss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mo 19.02.07 10:17 
sorry nocmal konkret
ich möchte einen button auf ein drawgrid ziehen(mit der maus) und möchte das bild des buttons im drawgrid platzieren.
wie geht das? Help me!
HILFE!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 19.02.07 11:31 
Ich hatte eigentlich auf konkrete Fragen mit Quelltext gewartet wo genau du etwas nicht verstehst. Denn es gibt im Internet einiges zum Thema DrawGrid...

Nun ja, hier mal ein kleines Beispiel... :roll:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls, Buttons;

const
  // Captiosn for the Rows (we have only one fixed column, but no row, wo we
  // only need one array
  Captions: array[0..4] of String = ('aaa', 'bb', 'cccc', 'ddd', 'e');

type
  TfrmMain = class(TForm)
    drgTest: TDrawGrid;
    btnTest1: TBitBtn;
    btnTest2: TBitBtn;
    btnTest3: TBitBtn;
    btnTest4: TBitBtn;
    procedure drgTestDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure drgTestDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure drgTestDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure PrepareImages;
  public
    { Public-Deklarationen }
  end;

var
  frmMain: TfrmMain;
  // Variable for the images which are to be displayed
  CellImages: array of array of TBitmap;

implementation

{$R *.dfm}

// Prepare the array and create all bitmaps (and resize the array with the
// images properly first)
procedure TfrmMain.PrepareImages;
var
  i, j: Integer;
begin
  SetLength(CellImages, drgTest.ColCount);
  for i := 0 to drgTest.ColCount - 1 do
  begin
    SetLength(CellImages[i], drgTest.RowCount);
    for j := 0 to drgTest.RowCount - 1 do
      CellImages[i, j] := TBitmap.Create;
  end;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  // Prepare the array with the images
  PrepareImages;
end;

procedure TfrmMain.drgTestDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  // Accept the drag operation if the source is a TBitBtn control
  Accept := Source is TBitBtn;
end;

procedure TfrmMain.drgTestDragDrop(Sender, Source: TObject; X, Y: Integer);
var
  ACol, ARow: Integer;
begin
  // Convert mouse coordinates to cell coordinates
  drgTest.MouseToCell(X, Y, ACol, ARow);
  // Assign the contents of the glyph bitmap to the one in the array
  CellImages[ACol, ARow].Assign(TBitBtn(Source).Glyph);
  // And invalidate the contents to repaint the control's canvas
  drgTest.Invalidate;
end;

procedure TfrmMain.drgTestDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if ACol = 0 then
    // if we have the first column then the caption has to be displayed
    drgTest.Canvas.TextOut(Rect.Left, Rect.Top, Captions[ARow])
  else
    // otherwise we display the image
    drgTest.Canvas.Draw(Rect.Left, Rect.Top, CellImages[ACol, ARow]);
end;

end.

Projekt mit diesem Quelltext im Anhang...
Einloggen, um Attachments anzusehen!